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





All commands from sorted by
Terminal - All commands - 12,230 results
curl -u user -d status="Tweeting from the shell" http://twitter.com/statuses/update.xml
wget --spider -v http://www.server.com/path/file.ext
typeset -f <function-name>
2009-08-04 17:07:21
User: log0

Display the code of a previously defined shell function.

find . -empty -type d -exec rmdir {} +
2009-08-04 16:55:34
User: jsiei97
Functions: find rmdir

A quick way to find and delete empty dirs, it starts in the current working directory.

If you do find . -empty -type d you will see what could be removed, or to a test run.

tar cf - dir_to_cp/ | (cd path_to_put/ && tar xvf -)
2009-08-04 16:51:31
User: jsiei97
Functions: cd tar

Just a copy of a big dir when you wan't things like ownership and date etc etc to be untouched.

Note: Updated with the ideas from "mpb".

echo linux|rev
2009-08-04 12:28:44
Functions: echo
Tags: rev


rev - reverse lines of a file or files


rev [file ...]


The rev utility copies the specified files to the standard output, reversing the order of characters in every line. If no files are specified, the standard input is read.


The rev command is part of the util-linux-ng package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.

exiftool '-Directory<DateTimeOriginal' -d %Y/%m/%d dir
2009-08-04 11:47:34
User: karel1980
Tags: exiftool

This command would move the file "dir/image.jpg" with a "DateTimeOriginal" of "2005:10:12 16:05:56" to "2005/10/12/image.jpg".

This is a literal example from the exiftool man page, very useful for classifying photo's. The possibilities are endless.

stat -f '%Sp %p %N' * | rev | sed -E 's/^([^[:space:]]+)[[:space:]]([[:digit:]]{4})[^[:space:]]*[[:space:]]([^[:space:]]+)/\1 \2 \3/' | rev
2009-08-04 08:45:20
User: vwal
Functions: rev sed stat

Since the original command (#1873) didn't work on FreeBSD whose stat lacks the "-c" switch, I wrote an alternative that does. This command shows also the fourth digit of octal format permissions which yields the sticky bit information.

rsync -a --delete --link-dest=../lastbackup $folder $dname/
2009-08-04 07:08:54
User: pamirian
Functions: rsync

dname is a directory named something like 20090803 for Aug 3, 2009. lastbackup is a soft link to the last backup made - say 20090802. $folder is the folder being backed up. Because this uses hard linking, files that already exist and haven't changed take up almost no space yet each date directory has a kind of "snapshot" of that day's files. Naturally, lastbackup needs to be updated after this operation. I must say that I can't take credit for this gem; I picked it up from somewhere on the net so long ago I don't remember where from anymore. Ah, well...

Systems that are only somewhat slicker than this costs hundreds or even thousands of dollars - but we're HACKERS! We don't need no steenkin' commercial software... :)

find -type f -exec md5sum '{}' ';' | sort | uniq --all-repeated=separate -w 33 | cut -c 35-
2009-08-04 07:05:12
User: infinull
Functions: cut find md5sum sort uniq

Calculates md5 sum of files. sort (required for uniq to work). uniq based on only the hash. use cut ro remove the hash from the result.

touch $2;firefox -print $1 -printmode PNG -printfile $2
2009-08-04 06:55:25
User: pamirian
Functions: touch

This requires the command-line print extension (see #2861 for more details). I use it to make up complex images with formatted text using CSS and whatnot. It's a lot slicker than imagemagick for certain things. Now imagine using a local webserver with PHP and a database to generate the images. Oh, the possibilities...

touch $2;firefox -print $1 -printmode PDF -printfile $2
2009-08-04 06:40:55
User: pamirian
Functions: touch

This uses the "command-line print" plugin for Firefox (http://torisugari.googlepages.com/commandlineprint2). This same plugin can also produce PNGs. On *nix, the file must exist; therefore the touch bit in front. Also, firefox seems to ignore saved user preferences when "printing" this way (margins, header, footer, etc.), so I had to tweak my ~/.mozilla/firefox/xxxxxxxx.default/prefs.js file by hand. Yup, that's *prefs.js* not user.js - apparently, firefox ignores my user.js file too...

cat frame/*.mpeg | ffmpeg -i $ID.mp3 -i - -f dvd -y track/$ID.mpg 2>/dev/null
2009-08-04 06:31:50
User: pamirian
Functions: cat

This is an extract from a larger script which formats the video for DVD. The videos I use have no audio track so I need to add one. Tweak as you like...

ffmpeg -loop_input -f image2 -r 30000/1001 -t $seconds -i frame/$num.ppm -y frame/%02d.mpeg 2>/dev/null
2009-08-04 06:25:47
User: pamirian

This is an extract from a larger script which makes up slideshow videos from images. $seconds is the number of seconds the video will last, and $num is a loop counter which numbers the videos for concat into a longer video later, so they will be in order. The dev/null bit on the end cuts ffmpeg's verbosity.

ifconfig | grep "0xffffffff" | awk '{ print $2 }' | xargs -n 1 ifconfig em0 delete
2009-08-04 05:18:36
User: vwal
Functions: awk grep ifconfig xargs

The example command deletes all aliases for network interface 'em0' assuming that the aliases have netmask of and the master IP has some other netmask (such as See here -> http://my.galagzee.com/2009/07/22/deleting-all-network-interface-aliases/ for more on the rationale of this command.

printf '\!:1\0\!:1\0\!:2' | mmencode | tr -d '\n' | sed 's/^/AUTH PLAIN /'
2009-08-04 05:04:50
User: vwal
Functions: printf sed tr

I use this as an alias:

alias authplain "printf '\!:1\0\!:1\0\!:2' | mmencode | tr -d '\n' | sed 's/^/AUTH PLAIN /'"


# authplain someuser@somedomain.com secretpassword

AUTH PLAIN c29tZXVzZXJAc29tZWRvbWFpbi5jb20Ac29tZXVzZXJAc29tZWRvbWFpbi5jb20Ac2VjcmV0cGFzc3dvcmQ=


curl -s http://isc.sans.org/sources.html|grep "ipinfo.html"|awk -F"ip=" {'print $2'}|awk -F"\"" {'print $1'}|xargs -n1 sudo iptables -A OUTPUT -j DROP -d > 2&>1
git --no-pager whatchanged -1 --pretty=medium <commit_hash>
alias z='zenity --info --text="You will not believe it, but your command has finished now! :-)" --display :0.0'
2009-08-03 16:38:29
User: bubo
Functions: alias

tired of switching to the console to check if some command has finished yet? if notify-send does not work on your box try this one... e.g. rsync -av -e /usr/bin/lsh $HOME slowconnection.bar:/mnt/backup ; z (now fire up X, do something useful, get notified if this stuff has finished).

ping -o -i 30 HOSTNAME && osascript -e 'tell app "Terminal" to display dialog "Server is up" buttons "It?s about time" default button 1'
2009-08-03 16:06:57
User: neologism
Functions: ping
Tags: macosx ping

When run on a mac, this command will bring up a dialog box in the Terminal when server HOSTNAME first responds to a ping.

copy(){ cp -v "$1" "$2"&watch -n 1 'du -h "$1" "$2";printf "%s%%\n" $(echo `du -h "$2"|cut -dG -f1`/0.`du -h "$1"|cut -dG -f1`|bc)';}
find . -type d -exec env d="$dest_root" sh -c ' exec mkdir -p -- "$d/$1"' '{}' '{}' \;
tmpfile=$(mktemp) && echo -e 'startup_message off\nscreen -t top htop\nsplit\nfocus\nscreen -t nethogs nethogs wlan0\nsplit\nfocus\nscreen -t iotop iotop' > $tmpfile && sudo screen -c $tmpfile
2009-08-03 10:14:02
User: Patola
Functions: echo screen sudo top

This command starts screen with 'htop', 'nethogs' and 'iotop' in split-screen. You have to have these three commands (of course) and specify the interface for nethogs - mine is wlan0, I could have acquired the interface from the default route extending the command but this way is simpler.

htop is a wonderful top replacement with many interactive commands and configuration options. nethogs is a program which tells which processes are using the most bandwidth. iotop tells which processes are using the most I/O.

The command creates a temporary "screenrc" file which it uses for doing the triple-monitoring. You can see several examples of screenrc files here: http://www.softpanorama.org/Utilities/Screen/screenrc_examples.shtml

ps -o comm= -p $(ps -o ppid= -p $$)
2009-08-03 07:41:21
User: olorin
Functions: ps

Get the name of the parent command. This might be helpful, if you need to react on that information. E. g. a script called directly via ssh has got sshd as parent, manually invoked the parent process will probably be bash

/sbin/kexec -l /boot/$KERNEL --append="$KERNELPARAMTERS" --initrd=/boot/$INITRD; sync; /sbin/kexec -e
2009-08-03 07:36:49
User: olorin
Tags: Linux boot kexec

If you are doing some tests which require reboots (e. g. startup skripts, kernel module parameters, ...), this is very time intensive, if you have got a hardware with a long pre-boot phase due to hardware checks.

At this time, kexec can help, which only restarts the kernel with all related stuff.

First the kernel to be started is loaded, then kexec -e jumps up to start it.

Is as hard as a reboot -f, but several times faster (e. g. 1 Minute instead of 12 on some servers here).