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,163 results
printf %d 0x`dd if=/dev/urandom bs=1 count=4 2>/dev/null | od -x | awk 'NR==1 {print $2$3}'`
2009-02-18 16:23:09
User: introp
Functions: awk od printf

Sometimes, in a shell script, you need a random number bigger than the range of $RANDOM. This will print a random number made of four hex values extracted from /dev/urandom.

svn diff $* | colordiff | less -r
2009-02-18 16:19:08
User: introp
Functions: diff less

I put this in a shell script called "svndiff", as it provides a handy decorated "svn diff" output that is colored (which you can't see here) and paged. The -r is required so less doesn't mangle the color codes.

wget -qO - http://infiltrated.net/blacklisted|awk '!/#|[a-z]/&&/./{print "iptables -A INPUT -s "$1" -j DROP"}'
2009-02-18 16:08:23
User: sil
Functions: wget

Blacklisted is a compiled list of all known dirty hosts (botnets, spammers, bruteforcers, etc.) which is updated on an hourly basis. This command will get the list and create the rules for you, if you want them automatically blocked, append |sh to the end of the command line. It's a more practical solution to block all and allow in specifics however, there are many who don't or can't do this which is where this script will come in handy. For those using ipfw, a quick fix would be {print "add deny ip from "$1" to any}. Posted in the sample output are the top two entries. Be advised the blacklisted file itself filters out RFC1918 addresses (10.x.x.x, 172.16-31.x.x, 192.168.x.x) however, it is advisable you check/parse the list before you implement the rules

grep -iR find_me ./
2009-02-18 15:38:59
User: lfamorim
Functions: grep

Searching for a String in Multiple Files With Grep

pg_dump -Ft -b -Uusername -hdb.host.com db_name > db.tar
find . -type l ! -exec test -e {} \; -print
2009-02-18 15:34:25
User: Shango1980
Functions: find test

Locate broken symlinks in the current directory. Also useful, to remove broken links:

find . -type l ! -exec test -e {} \; -print0 | xargs -0 rm
ffmpeg -i movie.avi -s 320x240 -b 1000k -vcodec wmv2 -ar 44100 -ab 56000 -ac 2 -y movie.wmv
2009-02-18 15:32:13
User: logik

I used this to cut down the file size of a 1gb .avi to about 200mb without sacrificing much quality.

dd if=10gb of=/dev/zero bs=1M count=10240
2009-02-18 15:30:29
User: logik
Functions: dd

Test your XFS filesystem and Raptor hard drives for write performance.

dd if=/dev/zero of=10gb bs=1M count=10240
2009-02-18 15:29:38
User: logik
Functions: dd

Test your XFS filesystem and Raptor hard drives for write performance.

ls -ad .*
2009-02-18 15:22:39
User: osantana
Functions: ls

List only hidden files (or directories). You also can use:

ls -lad .*
TF=`mktemp` && man -t YOUR_COMMAND >> $TF && gnome-open $TF
2009-02-18 15:18:35
User: furicle
Functions: man

Would be better if gnome-open would accept std in

Should be doable in KDE - anyone?

diff <(sort file1.txt) <(sort file2.txt)
2009-02-18 15:17:59
Functions: diff sort

Sees if two records differ in their entries, irrespective of order.

vim scp://username@host//path/to/somefile
wget -qO - snubster.com|sed -n '65p'|awk 'gsub(/<span><br>.*/,"")&&1'|perl -p -e 's:myScroller1.addItem\("<span class=atHeaderOrange>::g;s:</span> <span class=snubFontSmall>::g;s:&quot;:":g;s:^:\n:g;s:$:\n:'
2009-02-18 15:05:13
User: sil
Functions: wget

I've got this posted in one of my .bash_profiles for humor whenever I log in.

sudo dmidecode | grep Serial\ Number | head -n1
2009-02-18 14:54:28
User: nlinux
Functions: grep head sudo

This will give you the Dell Service tag number associated with your machine. Incredibly useful when you need that number for tech support or downloads.

tar zcf - user | pv /bin/gzip > /tmp/backup.tar.gz
2009-02-18 14:50:45
User: nlinux
Functions: tar

This command tar?s up a directory and sends the output to gzip, showing a rate of 223MB/s.

This may require you installing the pv command.

For debian based users out there:

sudo aptitude install pv
/usr/local/bin/OFPW -mode 1
2009-02-18 14:48:31
User: tomslick

Sets the Open Firmware to ask for password when selecting a boot volume other then the hd

watch -d "free -mt"
sed 's/\(..\)/\1:/g;s/:$//' mac_address_list
2009-02-18 14:38:37
User: sil
Functions: sed

I sometimes have large files of MAC addresses stored in a file, some databases need the information stored with the semicolon (makes for easier programming a device) others don't. I have a barcode to text file scanner which usually butchers MAC addresses so this was the fix> I initially did this in awk ;)

awk '{for(i=10;i>=2;i-=2)$0=substr($0,1,i)":"substr($0,i+1);print}' mac_address_list

find . -type d -exec chmod 0755 {} \;
2009-02-18 14:38:22
User: osantana
Functions: chmod find

WARNING! This command may set an invalid permission under your current directory.

This command will set the 0755 permissions to all directories under your current directory. An alternative version of this command is: find ~/.ssh -type d -exec chmod 0700 {} \;

find . -type f -exec chmod 0644 {} \;
2009-02-18 14:36:39
User: osantana
Functions: chmod find

WARNING! This command may set an invalid permission under your current directory.

This command will set the 0644 permissions to all files under your current directory. An alternative version of this command is: find ~/.ssh -type f -exec chmod 0600 {} \;

find . -name "*.py[co]" -exec rm -f {} \;
2009-02-18 14:32:28
User: osantana
Functions: find rm

This command will erase all bytecode versions of Python modules under the current directory.

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.

find . -iname "*.cpp" -exec perl -ni -e 'chomp; print "$_\n"' {} \;
2009-02-18 14:12:24
User: grundprinzip
Functions: find perl

Adds a newline to the end of all cpp files in the directory to avoid warnings from gcc compiler.