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.


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:



2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.




All commands from sorted by
Terminal - All commands - 11,490 results
long_command; say I am all done
2010-01-27 19:03:01
User: haivu
Tags: audio osx

I often run some command that takes a while to finish. By putting the say command afterward, I get an audio notification.

Please note that this command (say) only works on Mac OS X and not Linux.

ls | while read filename; do tar -czvf "$filename".tar.gz "$filename"; rm "$filename"; done
2010-03-29 08:10:38
User: Thingymebob
Functions: ls read rm tar

Compresses each file individually, creating a $fileneame.tar.gz and removes the uncompressed version, usefull if you have lots of files and don't want 1 huge archive containing them all. you could replace ls with ls *.pdf to just perform the action on pdfs for example.

cryptmount -m <name>
2012-01-17 18:02:47
User: totti

In order to create a new encrypted filing system managed by cryptmount,

you can use the supplied 'cryptmount-setup' program, which can be used

by the superuser to interactively configure a basic setup.

Alternatively, suppose that we wish to setup a new encrypted filing

system, that will have a target-name of "opaque". If we have a free

disk partition available, say /dev/hdb63, then we can use this directly

to store the encrypted filing system. Alternatively, if we want to

store the encrypted filing system within an ordinary file, we need to

create space using a recipe such as:

dd if=/dev/zero of=/home/opaque.fs bs=1M count=512


cryptmount --generate-key 32 opaque


cryptmount --prepare opaque


mke2fs /dev/mapper/opaque


cryptmount --release opaque


mkdir /home/crypt


cryptmount -m opaque


cryptmount -u opaque

For detail see sample output

SEARCHPATH=/var/; find $SEARCHPATH -type d -print0 | xargs -0 du -s 2> /dev/null | sort -nr | sed 's|^.*'$SEARCHPATH'|'$SEARCHPATH'|' | xargs du -sh 2> /dev/null
2011-07-06 08:21:58
User: moogmusic
Functions: du find sed sort xargs

This command lists all the directories in SEARCHPATH by size, displaying their size in a human readable format.

2009-02-17 01:23:39
User: roliver

Files saved on a windows machine use different ascii characters for lines turns. When viewing such files in VI the will most often have a ^M(control-VM) character at the end of each line. This command will remove all occurrences of that character

man emacs
2011-08-17 00:37:00
User: cwimmer
Functions: man

Emacs backs up previous versions by default.

echo $[RANDOM % 100] # range 0-99
2013-05-25 19:02:00
User: anapsix
Functions: echo

use it to stagger cronjob or to get a random number

increase the range by replacing 100 with your own max value

i="0"; while [ $i -lt 5 ] ; do xpenguins & i=$[$i+1] ; done
2009-12-27 21:05:33
User: eastwind

just replace the number 5 with the variable you want , and the xpenguins software with the one you want

tune2fs -l $(df -P / | tail -n1 | cut -d' ' -f1 ) | grep 'Filesystem created:'
echo -n "String to MD5" | md5sum | cut -f1 -d' '
2011-03-05 03:53:09
User: xakon
Functions: cut echo md5sum

Nothing special about hashing here, only the use of cut, I think, could result at fewer keystrokes.

ls -ltr |grep 'May 12'|awk '{print $9;}'|xargs rm -v
systemd-analyze plot | curl -sF file1=@- http://ompldr.org/upload | grep -P -o "(?<=File:).*(http://ompldr.org/.*)\<\/a\>" | sed -r 's@.*(http://ompldr.org/\w{1,7}).*@\1@'
find -iname '*.flac' | sed 's:/[^/]*$::' | uniq
2009-03-24 13:26:31
User: ar
Functions: find sed

Run this in your music folder, or give the path directly after "find".

The sed pattern filters away the basename.

html2text http://checkip.dyndns.org | grep -i 'Current IP Address:'|cut -d' ' -f4
2009-08-06 11:30:32
User: adonis28850
Functions: cut grep

The same as the other user, but smarter, using -d and -f

dd if=/dev/zero of=filename.file bs=1024 count=10240
2012-01-19 08:38:14
User: harpo
Functions: dd

Command to create a dummy file (full of nulls). Useful for testing e.g. file transfers when no file is at hand.

bs = blocksize, count = filesize in kilobytes

unrar x *.rar
2010-12-08 21:50:23
User: yababay

unrar e ... extracts all files into current directory, without archived subdirectories order. unrar x is more accurate command.

rsync -a -v --delete sending_directory target_directory
/usr/ucb/ps -auxgww
2009-12-28 12:36:04
User: sharfah

Depending on your installation, when you run ps you will only get the first 40 or so characters displayed. In order to view the entire string, use /usr/ucb/ps on Solaris.

echo `lcg-infosites --vo lhcb ce | cut -f 1| grep [[:digit:]]| tr '\n' '+' |sed -e 's/\ //g' -e 's/+$//'`|bc -l
2010-11-10 15:06:00
User: kbat
Functions: bc cut echo grep sed tr

Of course, this command must be executed at a GRID User Interface

lhcb - name of your VO, substitute it with the one you are interested it.

netstat -t -p --extend | grep USERNAME
2012-08-07 02:25:54
User: wr8cr8
Functions: grep netstat

This obtains a list of open connections that a user is connected to if he/she is using a SSH tunnel

find /path/ -type f -exec grep -l '<string of text>' {} \; | xargs sed -i -e 's%<string of text>%<new text string>%g'
gominify() { if [ $# -ne 2 ]; then echo 'gominify < src > < dst >'; return; fi; s="$1"; d="$2"; java -jar yui.jar $s >$d; if [ $? == 0 ]; then a=$( ls -sh $s | awk '{print $1}' ); b=$( ls -sh $d | awk '{print $1}' ); echo "Saved $s ($a) to $d ($b)"; fi;}
2010-08-03 10:19:24
User: meathive
Functions: awk echo ls

This command, or a derivative like it, is a must-have if you're a server administrator interested in website optimization: https://kinqpinz.info/?%C2%B6=287a7ba6

Command requires Yahoo's YUI, find it here: http://developer.yahoo.com/yui/

find . -mtime +30 -exec mv {} old/ \;
2014-02-09 23:05:41
User: minnmass
Functions: find mv
Tags: bash file

Use find's built-in "exec" option to avoid having to do any weirdness with quoting.

while [ 1 ]; do date; ls -l /path/to/dir; sleep 1; done
tar -tf <file.tar.gz> | parallel rm
2010-01-28 08:28:16
Functions: tar

xargs deals badly with special characters (such as space, ' and "). To see the problem try this:

touch important_file

touch 'not important_file'

ls not* | xargs rm

Parallel https://savannah.nongnu.org/projects/parallel/ does not have this problem.