commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. 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.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
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.
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:
First argument: string to put a box around.
Second argument: character to use for box (default is '=')
Same as command #4948, but shorter, and without the utility function.
The function 'box' takes either one or two arguments. The first argument is a line of text to be boxed, the second argument (optional) is a character to use to draw the box. By default, the drawing character will be '='.
The function 'n()' is a helper function used to draw the upper and lower lines of the box, its arguments are a length, and an character to print. (I used 'n' because 'line', 'ln' and 'l' are all commonly used)
underline() will print $1, followed by a series of '=' characters the width of $1. An optional second argument can be used to replace '=' with a given character.
This function is useful for breaking lots of data emitted in a for loop into sections which are easier to parse visually. Let's say that 'xxxx' is a very common pattern occurring in a group of CSV files.
You could run
grep xxxx *.csv
This would print the name of each csv file before each matching line, but the output would be hard to parse visually.
for i in *.csv; do printf "\n"; underline $i; grep "xxxx" $i; done
Will break the output into sections separated by the name of the file, underlined.
For those who hate navigating info pages, a shell function which will dump the contents to stdout, then page it through less, thus acting like 'man'.
Like command #4845, prints score, number of entries, and average score.
given lines of the form
each 'XXXX' will be replaced with a serial number between 0001 and 0004.
This replaces the current bash session with a new bash session, run as an interactive non-login shell... useful if you have changed /etc/bash.bashrc, or ~/.bashrc
If you have changed a startup script for login shells, use
exec bash -l
Suitable for re-running /etc/profile, ~/.bash_login and ~/.profile.
edit: chinmaya points out that
env - HOME=$HOME TERM=$TERM bash -s "exec bash -l"
will clear any shell variables which have been set... since this verges on unwieldy, might want to use
alias bash_restart='env - HOME=$HOME TERM=$TERM bash -s "exec bash -l"'
The function will take a comma separated list of items to be 'selected' by xsel -i:
smenu "First item to paste,Paste me #2,Third menu item"
You will then be prompted to choose one of the menu items. After you choose, you will be able to paste the string by clicking the middle mouse button.
The menu will keep prompting you to choose menu items until you break out with Control-C.
Set up X forwarding in PuTTY, with X display location set to :0.0
Launch PuTTY ssh session.
Launch Xming. Make sure that display is set to :0.0 (this is default).
echo "I'm going to paste this into WINDERS XP" | xsel -i
will insert the string into the windows cut and paste buffer.
Thanks to Dennis Williamson at stackoverflow.com for sharing...
Each shell function has its own summary line, as a comment. If there are multiple shell functions with the same name, the function with the highest number of votes is put into the file.
Note: added 'grep -v' to the end of the pipeline, to eliminate extraneous lines containing only '--'. Thanks to matthewbauer for pointing this out.
the 'set -x' mode can be exited by typing
This is useful when you're diffing two files of the same name in radically different directory trees. For example:
then run the command. Much easier on the eyes when you're looking back across your command history, especially if you're doing the same diff over and over again.
Creates a directory named with the current date, in the format YYYYMMDD. If you give it a directory name as an argument, it will create the new directory inside the specified directory.
This is an alternative to command #1993.
echo "..1234567." | cut -c $(range 3 7)
This version of tweet() doesn't require you to put quotes around the body of your tweet... it also prompts you for password. It will still barf on a '!' character.