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.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

All commands from sorted by
Terminal - All commands - 12,412 results
netstat -rn | awk '/UG/{print $2}'
2010-08-09 15:56:02
User: putnamhill
Functions: awk netstat

Tested on CentOS, Ubuntu, and MacOS.

cat -n FILE | grep -C3 "^[[:blank:]]\{1,5\}NUMBER[[:blank:]]"
2009-05-17 18:19:55
User: lv4tech
Functions: cat grep

This is useful for displaying a portion of a FILE that contains an error at line NUMBER

awk '/Table structure for table .table01./,/Table structure for table .table02./{print}' <file> > restored_table.sql
2010-08-09 18:23:13
User: din7
Functions: awk

This will look through file and print the data in between the pattern matches. It's great for restoring tables from a mysqldump backup. You can then import it back into your database with:

mysql -u <user> -h <host> <database> < restored_table.sql
(sleep 3; echo "MyAwesomePassword"; sleep 3) |socat - EXEC:'ssh [email protected] "hostname"',pty,setsid,ctty
2011-08-24 14:13:18
User: TommyBotten
Functions: echo sleep
Tags: socat pts

You should really use keys. Really. I'm serious.

But if you have to add your key, change password etc. for a long list of servers, this might help.

curl -s 'http://www.google.com/ig/api?weather=santa+monica,ca'| sed -ne "s/.*temp_c data..//;s/....humidity data.*//;p" | figlet
2012-06-25 03:58:15
User: monza241
Functions: sed

Change "santa+monica,ca" to your city name and state, or city name and country. In the USA, you can also use your zip code. In other countries, try using your postal code and country code.

dd if="\\?\Device\CdRom0" of=c:\temp\disc1.iso bs=1M --progress
2009-02-13 16:14:50
User: piyo
Functions: dd

dd for windows is available from http://www.chrysocome.net/dd

Tested with CD-ROMs like Linux install discs

I don't know about DVD-ROMs.

wget -qO - "http://ajax.googleapis.com/ajax/services/language/translate?langpair=|zh-cn&v=1.0&q=`xsel`" |cut -d \" -f 6
sudo aptitude remove -P $(dpkg -l|awk '/^ii linux-image-2/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic\nlinux-image-%s-generic\n",$0,$0,$0)}')
2011-04-25 05:19:57
User: Bonster
Functions: awk sed sudo

Same as 7272 but that one was too dangerous

so i added -P to prompt users to continue or cancel

Note the double space: "...^ii␣␣linux-image-2..."

Like 5813, but fixes two bugs: [1]This leaves the meta-packages 'linux-headers-generic' and 'linux-image-generic' alone so that automatic upgrades work correctly in the future. [2]Kernels newer than the currently running one are left alone (this can happen if you didn't reboot after installing a new kernel).

mkdosfs -F 32 /dev/sda1
socat READLINE EXEC:'sqlplus',pty,setsid,ctty
2011-08-24 14:17:41
User: TommyBotten

Perhaps a bit of a niche, but if you've even been frustrated by Oracles sqlplus command line tool for not supporting readline - have no fear. Socat is here to help you.

echo 'Dir.foreach("/usr/local/Cellar/cowsay/3.03/share/cows") {|cow| puts cow; system "fortune | cowsay -f /usr/local/Cellar/cowsay/3.03/share/cows/#{cow}" }' | ruby
2013-04-15 12:27:38
User: orkoden
Functions: echo

Shows a list of all installed cows saying a fortune. Also lists the cows names. Pic your favorite cow!

Needs cowsay, fortune and ruby installed. The path only applies to OS X with cowsay installed using homebrew. On Linux it might be /usr/share/cowsay/cows/ or similar. Uses ruby just because.

sleep 10 & perl -e [email protected]=qw(-Ooooo \oOooo |ooOoo /oooOo -ooooO \oooOo |ooOoo /oOooo);while(kill 0,'$!'){ print "\r",$s[$t++%($#s+1)];select(undef,undef,undef,0.2);}'
id 2>&1 > /sdcard/id;rsync -aP rsync:// /sdcard/t 2> /sdcard/rsync.err.log > /sdcard/rsync.log && return 123;fumanchu
find . -type d -exec mkdir /new/path/{} \;
2011-07-18 05:17:39
User: paulochf
Functions: find mkdir

It's not better than the former, just another possible way.

Found at http://www.linuxquestions.org/questions/linux-newbie-8/copy-directory-structure-only-208796/

Credits to whansard

The command finds all .mp3 files in all subfolders from where it's ran, catches its "relative path" and creates inside /new/path/ with the same "relative path".

PS: /new/path/ must exists

Use case: folder with flac files with tree structure ../artist/album/number-title.flac

1) convert flac->mp3 in the same folder: http://www.commandlinefu.com/commands/view/6341/convert-all-.flac-from-a-folder-subtree-in-192kb-mp3

2) search for mp3 files and recreate tree structure to another path: this command

3) move all mp3 files to that new folder: http://www.commandlinefu.com/commands/view/8854/move-mp3-files-to-another-path-with-existing-subtree-structure

cp -rf srcdir/* destdir
2012-06-25 13:01:03
User: jlaunay
Functions: cp
Tags: cp

As cp is often an alias to cp -i you can use \cp (or cp full path /bin/cp) to use the real cp command instead of its alias

gconftool-2 -t bool -s /desktop/gnome/interface/can_change_accels true
2009-03-10 14:53:33
User: prayer
Tags: gtk

Then, you can assign new accels to GTK menu actions pressing the keys while the option is active.

find . -empty -type f -execdir rm -f {} +
2010-11-17 14:15:47
User: maffo7
Functions: find rm

This command will remove only files, not directories: if you wish to remove both directories and files, just remove '-type f' from command above

curl -s http://www.drudgereport.com | sed -n '/<! MAIN HEADLINE>/,/<!-- Main headlines links END --->/p' | grep -oP "(?<=>)[^<].*[^>](?=<)"
gmake runtestsingle testsingle=udtime
2009-02-13 16:53:26
User: piyo

Given a GNU Make file version 3.81 with the following entries:

.PHONY: runtest


@for i in $(TESTAUTOEXES) ; do \

echo ">>>> Running test harness $$i" ; \

env $(RUNTESTENV) $$i ; done

.PHONY: runtestsingle

runtestsingle: $(ARCHNAME)/test/auto_$(testsingle).exe $(ARCHNAME)

@for i in $< ; do \

echo ">>>> Running test harness $$i" ; \

env $(RUNTESTENV) $$i ; done

(ARCHNAME is something like ix86-linux-gnu)

Instead of typing gmake runtest to run all the tests, you can run one specific test with the example command.

The sample output is from compiling a C++ program using Boost::Test testing framework.

perl -e 'print scalar localtime $ARGV[0],"\n" ' epoch
gdiff --unified=10000 input.file1 inpute.file2 | egrep -v "(^\+[a-z]|^\-[a-z])"| sort > outputfile.sorted
2009-06-18 20:35:00
User: slashdot
Functions: egrep sort

This commands will make it easier to select only common items between two files being compared. If your lines start with things other than lowercase a-z, adjust this Regex appropriately. Number of lines in the output has been set to no more than 10000, and should be adjusted as needed.

cdrecord -v path_to_iso_image.iso
file -sL /dev/sda7
salt -G 'os_family:Debian' cmd.run ' /usr/lib/update-notifier/apt-check --human-readable'
for i in *.tar.gz *.tgz; do tar -zxvf $i; done
2009-02-18 10:58:12
User: bohemicus
Functions: tar

This is a little bash script that will take all files following the *gz pattern in the directory and apply the tar -zxvf command to them.