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
tar -cf "../${PWD##*/}.tar" .
2013-11-06 11:15:38
User: joedhon
Functions: tar

should do the same as command #12875, just shorter.

cat schema.sql data.sql test_data.sql | mysql -u user --password=pass dbname
2009-03-24 08:39:40
User: tristan_ph
Functions: cat
Tags: mysql cat

Be aware of using the --password argument as it will appear your password in plain text on the screen. You may use -p argument instead, it will prompt you to enter you password in hidden mode.

wget http://www.discogs.com/search?q=724349691704 -O foobar &> /dev/null ; grep \/release\/ foobar | head -2 | tail -1 | sed -e 's/^<div>.*>\(.*\)<\/a><\/div>/\1/' ; rm foobar
2011-01-30 23:34:54
User: TetsuyO
Functions: grep head rm sed tail wget

Substitute that 724349691704 with an UPC of a CD you have at hand, and (hopefully) this oneliner should return the $Artist - $Title, querying discogs.com.

Yes, I know, all that head/tail/grep crap can be improved with a single sed command, feel free to send "patches" :D


echo -n "String to MD5" | md5sum | awk '{print $1}'
(echo 0; find [args...] -printf '%s +\n'; echo p) | dc
2011-08-17 07:49:55
User: wipu
Functions: echo find

Just an alternative. Here the output of the subshell statement is a complete script for dc so you can save it, manipulate it with some other tool or just debug it with less.

s=/etc/ssh/sshd_config;r=PermitRootLogin;cp $s{,.old}&& if grep $r $s;then sed "s/$r yes/$r no/" $s.old > $s; else echo $r no >> $s;fi
2011-01-30 23:41:59
User: kzh
Functions: cp echo grep sed
Tags: bash openssh

This will tighten up security for your box. The default value for PermitRootLogin sadly is 'yes'.

mysql -u <user> --password=<password> -e "SHOW COLUMNS FROM <table>" <database> | awk '{print $1}' | tr "\n" "," | sed 's/,$//g'
2009-10-29 13:42:17
User: maxmanders
Functions: awk sed tr

Useful when you need to write e.g. an INSERT for a table with a large number of columns. This command will retrieve the column names and comma-separate them ready for INSERT INTO(...), removing the last comma.

ffmpeg -i movie.mpg -vhook '/usr/lib/vhook/watermark.so -f overlay.png -m 1 -t 222222' -an mm.flv
fdupes DIRECTORY/ -r -d
2011-03-05 09:48:35
User: desmatron

allow you to find duplicates files in "DIRECTORY" and choose wich one to delete

fudpes must be installed: sudo apt-get install fdupes

( while read File; do mogrify -resize 1024 -quality 96 $File; done ) < filelist
2009-02-08 02:48:26
User: Corsair
Functions: read

Imagemagick library is used. If image format is not JPEG, the "quality" option should not be issued.

sudo service bluetooth restart
kill -9 $(ps -ef | grep [h]ttpd | awk '{print $2}')
echo -e "CHECK=SAMPLE" output --command_to_long
2013-04-03 08:46:47
User: techie
Functions: echo

This is longer than others on here. The reason for this is I have combined two different matrix commands so it would work on all computers. I logged onto my server through a computer and it worked fine. I logged into my server through a mac and it looked $4!t so I have made one that works through both.

ps -e -o pid,vsz,comm= | sort -n -k 2
2014-05-14 00:36:50
Functions: ps sort

left-most column is PID, middle is virtual memory being consumed, right-most is actual process.

find . -size 0 -print0 | xargs -0 rm
2009-10-29 14:10:02
User: osvaldofilho
Functions: find xargs

The command find search commands with size zero and erase them.

date MMDDhhmmYYYY
2010-05-29 08:26:13
User: christian773
Functions: date

date MMDDhhmmYYYY

date MMDDhhmm

# example 27.12.1975 08:00

date 122708001975

c="cp -a";e="~";echo -e "\npaste\n";i=0;k="1"; while [[ "$k" != "" ]]; do read -a k;r[i]=$k;((i++));done;i=0;while :;do t=${r[i]};[ "$t" == "" ] && break; g=$(echo $c ${r[i]} $e);echo -e $g "\ny/n?";read y;[ "$y" != "n" ] && eval $g;((i++));done
2011-12-04 12:45:44
User: knoppix5
Functions: echo eval read


command [options] [paste your variable here] parameter

command [options] [paste entire column of variables here] parameter


(hard-code command "c" and parameter "e" according to your wishes: in example shown command = "cp -a" and parameter = "~")


- Quick exchange only variable part of a long command line

- Make variable part to be an entire column of data (i.e. file list)

- Full control while processing every single item


Paste column of data from anywhere. I.e. utilize the Block Select Mode to drag, select and copy columns (In KDE Konsole with Ctrl+Alt pressed, or only Ctrl pressed in GNOME Terminal respectively).


You can paste only one single variable in a row. If there are more space separated variables in a row only first one will be processed, but you can arrange your variables in a column instead. To transpose rows to columns or vice versa look at Linux manual pages for 'cut' and 'paste'.


- add edit mode to vary command "c" and parameter "e" on the fly

- add one edit mode more to handle every list item different

- add y/n/a (=All) instead of only y(=default)/n to allowed answers


The code is not optimized, only the basic idea is presented here. It's up to you to shorten code or extend the functionality.

sed -i 's/http:\/\/old\/new\///g' index.html
tar -cf - folder/ | gpg -c > folder.tpg
2009-05-08 19:20:08
User: copremesis
Functions: gpg tar

gpg's compression is as suitable as gzip's however your backups can now be encrypted.

to extract use:

gpg < folder.tpg | tar -xf -
fetch -q -o - http://ipchicken.com | egrep -o '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}'
2009-08-06 11:57:44
User: spackle
Functions: egrep

Same thing as above, just uses fetch and ipchicken.com

disper --displays=auto -e -t left
2010-01-28 06:46:56

Disper: http://willem.engen.nl/projects/disper/

Moving Gnome Panels to the external screen is done using gconf-editor, changing property "/apps/panel/toplevels/top_panel_screen0/monitor", as well as "/apps/panel/toplevels/bottom_panel_screen0/monitor" to int value "1". This can be done from the command line using '

gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/monitor" --type integer "1"' so a nice script can be written.

wget -O - http://checkip.dyndns.org|sed 's/[^0-9.]//g'
svn log -v | less
for i in *; do j=`echo $i | cut -d "-" -f1`; j=$j; mv $i $j; done
2011-03-06 11:58:37
User: jaimerosario
Functions: cut mv

Renames files eliminating suffix, in this case everything after "-" is cutted. Just change "-" with the character you need.

grep -E '<DT><A|<DT><H3' bookmarks.html | sed 's/<DT>//' | sed '/Bookmarks bar/d' | sed 's/ ADD_DATE=\".*\"//g' | sed 's/^[ \t]*//' | tr '<A HREF' '<a href'
2011-05-26 22:21:01
User: chrismccoy
Functions: grep sed tr
Tags: sed grep chrome

chrome only lets you export in html format, with a lot of table junk, this command will just export the titles of the links and the links without all that extra junk