What's this?

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/

Get involved!

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.

Universal configuration monitoring and system of record for IT.

Stay in the loop…

Follow the Tweets.

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

Subscribe to the feeds.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Commands by raphink from sorted by
Terminal - Commands by raphink - 31 results
git log --pretty=oneline b56b83.. | wc -l
if [ "x${a/$b/}" != "x$a" ]; then echo "'$b' is in '$a'"; fi
if grep -q "$b" <<<$a; then echo "'$b' was found in '$a'"; fi
2009-03-02 14:55:56
User: raphink
Tags: man

Launch a command from within a manpage, vim style. This is rather trivial, but can be very useful to try out the functions described in a manpage without actually quitting it (or switching to another console/screen/...).

dpkg --compare-versions 1.0-2ubuntu5 lt 1.1-1~raphink3 && echo y || echo n
2009-02-28 18:01:59
User: raphink
Functions: echo
Tags: Debian Ubuntu

Compares two versions with dpkg. It is not always obvious what version dpkg/apt will consider to be more recent. Operators include the following :

* These treat an empty version as earlier than any version: lt le eq ne ge gt.

* These treat an empty version as later than any version: lt-nl le-nl ge-nl gt-nl.

* These are provided only for compatibility with control file syntax: < > >.

This command doesn't output anything. It only returns with status 0 or 1, hence the echo "y" || echo "n" to get an output.

ssh -MNf <user>@<host>
2009-02-26 14:11:19
User: raphink
Functions: ssh

Create a persistent SSH connection to the host in the background. Combine this with settings in your ~/.ssh/config:

Host host

ControlPath ~/.ssh/master-%r@%h:%p

ControlMaster no

All the SSH connections to the machine will then go through the persisten SSH socket. This is very useful if you are using SSH to synchronize files (using rsync/sftp/cvs/svn) on a regular basis because it won't create a new socket each time to open an ssh connection.

tar cpfP - $(find <somedir> -type f -name *.png) | ssh user@host | tar xpfP -
2009-02-26 00:01:30
User: raphink
Functions: find ssh tar


* Adjust the find command to your own filters.

* The -P flag forces to keep absolute paths in the tarball, so that you can be sure that the exact same file hierarchy will be created on the second machine.

mii-tool [if]
eject -T [cdrom_device]
2009-02-25 23:53:03
User: raphink
Functions: eject
Tags: device

Opens or closes the cdrom device.

date --iso
2009-02-25 23:50:40
User: raphink
Functions: date

Useful to archive files once a day:

cp file file.$(date --iso)
^Z then bg
^A ?
2009-02-25 23:42:33
User: raphink
Tags: screen

Displays a list of all the basic keyboard shortcuts in screen.

:split <file>
2009-02-25 23:41:22
User: raphink

You can then switch from a file to another with ^W^W

TMPROOT=/tmp; TMPDIR=$(mktemp -d $TMPROOT/somedir.XXXXXX); TMPFILE=$(mktemp $TMPROOT/somefile.XXXXXX); trap "rm -rf $TMPDIR $TMPFILE; exit" INT TERM EXIT; some treatment using $TMPDIR and $TMPFILE; exit 0
2009-02-24 09:35:22
User: raphink
Functions: exit mktemp trap

Cleanly create tempfiles using mktemp and remove them using traps instead of removing them in the end of the script. This way, you make sure the tempfiles are removed properly even if the script is killed or interrupted.

For a user script in KDE4, you can set TMPROOT using :

TMPROOT=$(kde4-config --path tmp)
FLOOR=0; RANGE=10; number=0; while [ "$number" -le $FLOOR ]; do number=$RANDOM; let "number %= $RANGE"; done; echo $number
2009-02-20 09:33:56
User: raphink
Functions: echo
Tags: bash

This one-liner outputs a random number between the values given for FLOOR and RANGE.

apt-cache dotty apache2 | dot -T png | display
2009-02-18 14:27:31
User: raphink
Functions: apt dot

Requires: imagemagick and graphviz

On Debian systems, displays a graph of package dependencies. Works also with other image formats, like svg :

apt-cache dotty bash | dot -T svg | display
sudo -l
2009-02-18 14:17:39
User: raphink
Functions: sudo

List the commands you have the right to use with sudo.

caff <keyid>
2009-02-18 14:09:03
User: raphink
Tags: GPG

Requires: signing-party (on Debian).

Note: you need a working MTA on your machine.

echo "foo bar" | sudo tee -a /path/to/some/file
2009-02-18 13:54:25
User: raphink
Functions: echo sudo tee

This is the solution to the common mistake made by sudo newbies, since

sudo echo "foo bar" >> /path/to/some/file

does NOT add to the file as root.


sudo echo "foo bar" > /path/to/some/file

should be replaced by

echo "foo bar" | sudo tee /path/to/some/file

And you can add a >/dev/null in the end if you're not interested in the tee stdout :

echo "foo bar" | sudo tee -a /path/to/some/file >/dev/null
update-alternatives --config java
2009-02-18 13:43:41
User: raphink
Tags: Debian Ubuntu

On Debian systems, choose which command provides java. Works for all alternatives listed in /etc/alternatives.

ssh user@host cat /path/to/some/file | xclip
2009-02-18 10:56:38
User: raphink
Functions: cat ssh
Tags: X X11

Have you ever had to scp a file to your work machine in order to copy its contents to a mail? xclip can help you with that. It copies its stdin to the X11 buffer, so all you have to do is middle-click to paste the content of that looong file :)

install -o user -g group -m 755 /path/to/file /path/to/dir/
2009-02-18 10:46:19
User: raphink
Functions: install

This is useful when you want to copy a file and also force a user, a group and a mode for that file.

Note: if you want to move that file instead of copying it, you can use

install -o user -g group -m 755 /path/to/file /path/to/dir/ && rm -f /path/to/file

which will remove the file only if the install command went fine.

grep -v "^\($\|#\)" <filenames>
2009-02-16 21:40:09
User: raphink
Functions: grep

Filter comments and empty lines in files. I find this very useful when trying to find what values are actually set in a very long example config file.

I often set an alias for it, like :

alias nocomment='grep -v "^\($\|#\)"'

cd !$
2009-02-16 21:33:14
User: raphink
Functions: cd

!$ recalls the last argument of the previous command. This is very useful when you have to operate several operations on the same file for example.

kquitapp plasma
2009-02-16 21:27:16
User: raphink
Tags: KDE

KDE4 is great, but still a bit buggy, and sometimes plasma requires to be restarted. Instead of quitting it with "killall plasma", which might loose your preferences (widgets, etc.), kquitapp will cleanly quit it. Tip: you can type this in the "Alt+F2" window, and then type "plasma" in Alt+F2 again to restart plasma (be patient though...).