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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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



All commands from sorted by
Terminal - All commands - 12,419 results
rpm -qa --queryformat "%{NAME} %{ARCH}\n"
2009-03-18 15:19:21
User: angrox
Functions: rpm

Lists all installed RPM packages with name and architecture, which is useful to check for compability packages (+ required i386 packages) on a 64bit system.

^[c (ctrl-v esc-c)
2009-03-18 15:15:24
User: angrox

Resets a scrambled terminal into its orignal state.

echo '123/7' |bc -l |xargs printf "%.3f\n"
exiv2 -M"set Exif.Photo.DateTimeOriginal `date "+%Y:%m:%d %H:%M:%S"`" filename.jpg
ssh-keygen; ssh-copy-id [email protected]; ssh [email protected]
2009-03-18 07:59:33
User: bwoodacre
Functions: ssh ssh-keygen
Tags: openssh

This command sequence allows simple setup of (gasp!) password-less SSH logins. Be careful, as if you already have an SSH keypair in your ~/.ssh directory on the local machine, there is a possibility ssh-keygen may overwrite them. ssh-copy-id copies the public key to the remote host and appends it to the remote account's ~/.ssh/authorized_keys file. When trying ssh, if you used no passphrase for your key, the remote shell appears soon after invoking ssh [email protected]

ssh [email protected] "cd targetdir; tar cfp - *" | dd of=file.tar
2009-03-18 07:43:22
User: bwoodacre
Functions: dd ssh

This invokes tar on the remote machine and pipes the resulting tarfile over the network using ssh and is saved on the local machine. This is useful for making a one-off backup of a directory tree with zero storage overhead on the source. Variations on this include using compression on the source by using 'tar cfvp' or compression at the destination via

ssh [email protected] "cd dir; tar cfp - *" | gzip - > file.tar.gz
for file in `find . -type f`; do cat $file; done | wc -l
echo -n 'text to be encrypted' | openssl md5
2009-03-18 00:11:46
User: Zenexer
Functions: echo

Thanks to OpenSSL, you can quickly and easily generate MD5 hashes for your passwords.

Alternative (thanks to linuxrawkstar and atoponce):

echo -n 'text to be encrypted' | md5sum -

Note that the above method does not utlise OpenSSL.

2009-03-18 00:03:42
User: Zenexer
Functions: top

A simple but effective replacement for ps aux. I used to waste my time running ps over and over; top is the way to go. It also allows complex sorting options. Press q to exit "nicely" (Ctrl + C is always an option, of course). Note that the list updates each second, resorting in the process; if you're trying to grab a specific PID, you might be better off with ps.


Alternatively, htop is available, though it may not come pre-installed. htop is slightly more interactive than top and includes color coding, visuals, and a nice interface for selecting and then killing processes. (Thanks to bwoodacre for this great tool.)

^Z $bg $disown
2009-03-17 21:52:52
User: fall0ut

You're running a script, command, whatever.. You don't expect it to take long, now 5pm has rolled around and you're ready to go home... Wait, it's still running... You forgot to nohup it before running it... Suspend it, send it to the background, then disown it... The ouput wont go anywhere, but at least the command will still run...

sed ':a;N;$!ba;s/\n/ /g'
2009-03-17 20:54:04
User: cidiom
Functions: sed
Tags: Linux

Ever had a file with a list of numbers you wanted to add, use:

cat file | sed ':a;N;$!ba;s/\n/+/g' | bc
echo "test" | lp -d $PRINTER
2009-03-17 20:07:41
User: nauseaboy
Functions: echo lp

This will send a test print job to a networked printer.

vos listvldb | agrep LOCKED -d RWrite | grep RWrite: | awk -F: '{print $2}' | awk '{printf("%s ",$1)} END {printf("\n")}'
2009-03-17 19:55:39
User: mpb
Functions: awk grep

This command shows if there are any locked AFS volumes.

The output is a list of AFS volume IDs (or nothing if there are none locked).

mplayer tv:// -tv driver=v4l:width=352:height=288
2009-03-17 19:37:23
User: Robertof

Show the webcam output with mplayer.

startx > startx.log 2>&1
shopt -s nocaseglob
2009-03-17 17:51:42
User: josx

Change bash autocomplete case search to insensitive when pressing tab for completion.

shopt -s cdspell
ls -1 | rename 's/\ /_/'
2009-03-17 17:33:41
Functions: ls rename

Substitute spaces in filename with underscore, it work on the first space encountered.

for i in `find /sys/devices/*/*/usb* -name level` ; do echo -n "$i: " ; cat $i ; done
rpm -qa --queryformat '%{installtime} \"%{vendor}\" %{name}-%{version}-%{release} %{installtime:date}\n' | grep "Thu 05 Mar"
2009-03-17 13:38:20
User: mpb
Functions: grep rpm

Find out which RPMs were installed on a particular date.

These would (naturally) include update RPMs.

This example shows searching for "Thu 05 Mar" (with grep).

Alternatively, pipe it to less so you can search inside less (with less's neat text highlighting of the search term):

rpm -qa --queryformat '%{installtime} \"%{vendor}\" %{name}-%{version}-%{release} %{installtime:date}\n' | less # (this example) search term: Thu 05 Mar

play $audio_file
2009-03-17 11:30:02
User: mpb

"play" is part of "SoX"

SoX - Sound eXchange, the Swiss Army knife of audio manipulation.

For details, see: man sox

find -maxdepth 1 -type d -print0 | xargs -0 -I {} tar -cvzf {}.tar.gz {}
2009-03-17 11:12:53
User: piemme
Functions: find tar xargs

Create backup (.tar.gz) for all first-level directory from current dir.

lynx -accept_all_cookies -cmd_script=/your/keystroke-file
2009-03-17 00:38:36
User: Alanceil

This command will tell lynx to read keystrokes from the specified file - which can be used in a cronjob to auto-login on websites that give you points for logging in once a day *cough cough* (which is why I used -accept_all_cookies).

For creating your keystroke file, use:

lynx -cmd_log yourfile
:!cp % %-
2009-03-17 00:34:24
User: mpb

At the start of a vi session and *before* saving any changes use ":!cp % %-" to make a backup of the current file being edited.

example: vi /data/some/long/path/file

:!cp% %-

creates /data/some/long/path/file-

# indicates a comment in shell
2009-03-16 23:15:33
User: mpb

Using the "#" in shell is surprisingly useful.

Some of the uses I found:

a) As a visible copy buffer in shell history (caveat: do not use for passwords :-)

b) To build complex commands until ready then hit the HOME, DEL, ENTER keys to run it

c) Placing reference data into shell history (search for tags with CTRL-R TAGNAME)

d) Putting aside a "work in progress" command to focus on another task (HOME # ENTER)