Hide

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.

Hide

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:

Hide

News

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.
Hide

Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 11,490 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
1

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
2

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
33

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
-4

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
13

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
0

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
-1

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
1

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

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

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
8

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
4

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
-2

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
14

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
4

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
0

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
5

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
-5

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
-7

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
3

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
7

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
8

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
0

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