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,272 results
rm ./-filename
2009-02-18 18:36:25
User: starchox
Functions: rm

Using the redundant ./ directory information prevents the dash from occurring at the beginning of the filename, and being interpreted as an option of the rm command.

Also works using:

rm -- -filename
mysql -uadmin -p`cat /etc/psa/.psa.shadow` -e "use psa; select accounts.password from accounts INNER JOIN sys_users ON accounts.id=sys_users.account_id WHERE sys_users.login='xxxx';"
2009-02-18 17:26:41
User: darkon1365

This will print to the screen password for the user specified in "sys_users.login='xxxx';. This is for Plesk servers only.

vimdiff /path/to/file scp://remotehost//path/to/file
cat /dev/mem > /dev/audio
unset files i; set -f; O=$IFS; while IFS= read -r -d $'\0' files[i++]; do :; done < <(find . -name '*.avi' -print0) && IFS=$O; set +f && echo "Running: mplayer \"${files[ $(( $RANDOM % ${#files[@]} )) ]}\""
2009-02-18 16:53:57
User: DEinspanjer
Functions: echo find read set unset

unsets variables used by the one-liner

sets up the IFS bash variable to not be affected by whitespace and disables extra glob expansion

uses read to slurp the results of the find command into an array

selects an element of the array at random to be passed as an argument to mplayer

last | grep -v "^$" | awk '{ print $1 }' | sort -nr | uniq -c
2009-02-18 16:38:59
User: hkyeakley
Functions: awk grep last sort uniq

This command takes the output of the 'last' command, removes empty lines, gets just the first field ($USERNAME), sort the $USERNAMES in reverse order and then gives a summary count of unique matches.

perl -pe '$_=reverse;s/\d{3}(?=\d)(?!.*?\.)/$&,/g;$_=reverse'
2009-02-18 16:34:18
User: sil
Functions: perl

Insert a comma where necessary when counting large numbers. I needed to separate huge amounts of packets and after 12+ hours of looking in a terminal, I wanted it in readable form.

blockdev --setra 1024 /dev/sdb
2009-02-18 16:27:01
User: starchox

(WARN) This will absolutely not work on all systems, unless you're running large, high speed, hardware RAID arrays. For example, systems using Dell PERC 5/i SAS/SATA arrays. If you have a hardware RAID array, try it. It certainly wont hurt.

You may be can test the speed disk with some large file in your system, before and after using this:

time dd if=/tmp/disk.iso of=/dev/null bs=256k

To know the value of block device parameter known as readahead.

blockdev --getra /dev/sdb

And set the a value 1024, 2048, 4096, 8192, and maybe 16384... it really depends on the number of hard disks, their speed, your RAID controller, etc. (see sample)

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