This is for bash - make an alias - also a good blueprint for making aliases that take arguments to functions. If for Solaris use "-size +${1}000000c" to replace "-size +${1}M" Show Sample Output
The result of this command is a tar with all files that have been modified/added since revision 1792 until HEAD. This command is super useful for incremental releases.
ksh's version of cd has an optional syntax where you can type "cd old new" and it will replace "old" with "new" in your current directory and take you there. This is very handy when you have a parallel directory structure, like source and object directories. As suggested, you can just type cd ${PWD/old/new} to get this in bash, but this function in your .bashrc will let you type the ksh cd syntax and avoid typing the special characters while preserving other cd functionality. Show Sample Output
{ ... } vs ( ... ) reduces the process count, I believe. Typically, I use this logic to redirect a series of commands to a pipe -- { command1 args1 ; command2 args2}|less -- or file -- { command1 args1 ; command2 args2}>foo -- or to spawn the series as a background process -- { ... } & .
Bash function copies a file prefixed with a version number to a subdirectory Show Sample Output
Just to avoid link to itself
Improved version of command #8425. This way, the default browser is used, as opposed to Firefox.
Inspired by: http://www.commandlinefu.com/commands/view/8744/search-google-on-os-x
#!/bin/bash
if [ -n "$1" ]
then
firefox 'http://www.google.com/search?q="'$1'"'
else
firefox 'http://www.google.com'
fi
Ive aliased this script as 'google' on my system and I can type 'google "search terms"' to open firefox with my search terms. My first post here, if there are any improvements to be made please let me know in the comments.
In order to create, let's say, 10 directories with a single process we can use the command:
mkdir test{1,2,3,4,5,6,7,8,9,10}
something extremely boring to type! Why not use seq?
seq -s, 1 10
and use its output inside the curly braces?
The obvious solution
mkdir test{$(seq -s, 1 10)}
is, unfortunately, too naive and doesn't work. The answer is the order of the shell expansions (feature of Bourne Shell, actually), where brace expansion happens before command substitution (according to Bash's manual).
The solution is to put another level of substitution, using the powerful and mystic command eval.
I found the trick in a similar problem in the post at http://stackoverflow.com/questions/6549037/bash-brace-expansion-in-scripts-not-working-due-to-unwanted-escaping
Pi also says hello world!
nothing special Show Sample Output
You can find a command's history event number via the `history` command.
You can also put the history event number in your prompt: \! for bash, or %h for zsh.
Finally, I would like to point out that by "number", I mean POSITIVE INTEGER. Not, say, a letter, such as 'm'. Examples:
!1
or
!975
Show Sample Output
Change "sort -f" to "sort" and "uniq -ic" to "uniq -c" to make it case sensitive. Show Sample Output
Find all files in /var/spool/mqueue older than 7 days, pass to perl to efficiently delete them (faster than xargs or -exec when you've got millions or hundreds of thousands to delete). Naturally the type, directory, and file age vars can be adjusted to meet your specific needs.
Expand a URL, aka do a head request, and get the URL. Copy this value to clipboard.
WIDTHL=10 and WIDTHR=60 are setting the widths of the left and the right column/bar. BAR="12345678" etc. is used to create a 80 char long string of "="s. I didn't know any shorter way. If you want to pipe results into it, wrap the whole thing in ( ... ) I know that printing bar graphs can be done rather easily by other means. Here, I was looking for a Bash only variant. Show Sample Output
Just hold Ctrl-R and start typing a string (e.g. ssh). The shell will search for that string in the command history. Keep pressing Ctrl-R to cycle through all commands matching pattern. This works in other "sub-shells" too, like a python interactive session. Show Sample Output
Enhancement for the 'busy' command originally posted by busybee : less chars, no escape issue, and most important it exclude small files ( opening a 5 lines file isn't that persuasive I think ;) ) This makes an alias for a command named 'busy'. The 'busy' command opens a random file in /usr/include to a random line with vim.
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for: