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,360 results
man ls | col -b > ~/Desktop/man_ls.txt
2009-06-13 11:49:33
User: vigo
Functions: col ls man

You can convert any UNIX man page to .txt

unrar e file.part1.rar; if [ $? -eq 0 ]; then rm file.part*.rar; fi
2009-06-13 11:11:43
User: mrttlemonde
Functions: rm

It's also possible to delay the extraction (echo "unrar e ... fi" |at now+20 minutes) wich is really convenient!

a=`printf "%*s" 16`;b=${a//?/{0..1\}}; echo `eval "echo $b"`
chronic () { t=$1; shift; while true; do $@; sleep $t; done & }
2009-06-13 05:57:54
User: rhythmx
Functions: sleep

Chronic Bash function:

chronic 3600 time # Print the time in your shell every hour chronic 60 updatedb > /dev/null # update slocate every minute

Note: use 'jobs' to list background tasks and fg/bg to take control of them.

for i in *.tar.gz; do tar -xzf $i; done
2009-06-13 03:58:48
User: kureikain
Functions: tar
Tags: tarball

You can flexibly change file pattern(*.tar.gz) and uncompress command to other job!

Example, remove all files :

for i in *.tar.gz; do rm $i; done

(Just for example, because if you really want to remove file, simply use wildcard like this rm *.tar.gz)

egrep -r '(render_message|multipart).*('`find app/views -name '*.erb' | grep mailer | sed -e 's/\..*//' -e 's/.*\///' | uniq | xargs | sed 's/ /|/g'`')' app/models
ldapsearch -h ldapserver.willeke.com -p389 -b "" -s base -D cn=admin,ou=administration,dc=willeke,dc=com -w secretpwd "(objectclass=*)" chainings removeEntryOps referralsReturned listOps modifyRDNOps repUpdatesIn repUpdatesOut strongAuthBinds addEntryOps
2009-06-12 13:28:18
User: jwilleke
Tags: ldap

Find statistics for an Edirectory server form LDAPsearch.

We have a lot more examples at:


The full command got shut off it is:

ldapsearch -h ldapserver.willeke.com -p636 -e C:\mydata\treerootcert.der -b "" -s base -D cn=admin,ou=administration,dc=willeke,dc=com -w secretpwd "(objectclass=*)" chainings removeEntryOps referralsReturned listOps modifyRDNOps repUpdatesIn repUpdatesOut strongAuthBinds addEntryOps compareOps wholeSubtreeSearchOps modifyEntryOps searchOps errors simpleAuthBinds inOps oneLevelSearchOps inBytes abandonOps bindSecurityErrors securityErrors unAuthBinds outBytes extendedOps readOps dsaName directoryTreeName vendorVersion vendorName

mysqldump [options] |gzip ->mysqldump-$(date +%Y-%m-%d-%H.%M.%S).gz
2009-06-12 12:42:59
Functions: date gzip

Performs a mysqldump and gzip-compresses the output file with a timestamp in the resulting dump file. Inspect the file for integrity or fun with this command afterward, if you desire:

zcat mysqldump-2009-06-12-07.41.01.tgz | less
sed '/MARKER/{N;s/THIS/THAT/}'
2009-06-12 02:29:50
User: mungewell
Functions: sed
Tags: sed gnuplot

I've been auto-generating some complex GnuPlots; with multiplots the first plot of each group needs to be a 'plot' whereas the others need to be 'replots' to allow overplotting/autoscaling/etc to work properly.

This is used to replace only the first instance of 'replot'.

function my_irc { tmp=`mktemp`; cat > $tmp; { echo -e "USER $username x x :$ircname\nNICK $nick\nJOIN $target"; while read line; do echo -e "PRIVMSG $target :$line"; done < $tmp; } | nc $server > /dev/null ; rm $tmp; }
2009-06-11 22:14:48
User: Josay
Functions: cat echo read rm
Tags: netcat irc nc
command | my_irc

Pipe whatever you want to this function, it will, if everything goes well, be redirected to a channel or a user on an IRC server.

Please note that :

- I am not responsible of flood excesses you might provoke.

- that function does not reply to PINGs from the server. That's the reason why I first write in a temporary file. Indeed, I don't want to wait for inputs while being connected to the server. However, according to the configuration of the server and the length of your file, you may timeout before finishing.

- Concerning the server, the variable content must be on the form "irc.server.org 6667" (or any other port). If you want to make some tests, you can also create a fake IRC server on "localhost 55555" by using

netcat -l -p 55555

- Concerning the target, you can choose a channel (beginning with a '#' like "#chan") or a user (like "user")

- The other variables have obvious names.

mkdir phrack66; (cd phrack66; for n in {1..17} ; do echo "http://www.phrack.org/issues.html?issue=66&id=$n&mode=txt" ; done | xargs wget)
2009-06-11 21:42:42
Functions: cd echo mkdir xargs

Nice reading in the morning on the way to work, but sadly the .tar.gz for the whole issue 66 is not on phrack's website yet. So use wget to download.

cd <YOUR_DIRECTORY>; for i in `ls ./`; do tar czvf "$i".tar.gz "$i" ; done
2009-06-11 18:33:27
User: ElAlecs
Functions: cd tar

Very simple and useful, you need to change the word "directory" for your directory

ldapsearch -H ldap://localhost:389 -D cn=username,ou=users,dc=domain -x -W -b ou=groups,dc=domain '(member=cn=username,ou=users,dc=domain)' | grep ^dn | sed "s/dn\: cn=\([^,]*\),ou=\([^,]*\),.*/\2 \1/"
2009-06-11 14:50:11
User: nitehawk
Functions: grep sed

This expression looks for groups inside of a GroupOfNames class element, that is itself inside one (or many) Organizational Unit (ou) nodes in the ldap tree. Give you a quick dump of all the groups the user belongs to. Handy for displaying on a webpage.

ldapsearch -LLL -H ldap://activedirectory.example.com:389 -b 'dc=example,dc=com' -D 'DOMAIN\Joe.Bloggs' -w [email protected]' '(sAMAccountName=joe.bloggs)'
2009-06-11 13:07:11
User: greppo
Tags: ldap

These are the parameters to ldapsearch (from ldap-utils in Ubuntu), for searching for the record for Joe Blogg's user. sAMAccountName is the LDAP field that ActiveDirectory uses to store the user name. 'DOMAIN\Joe.Bloggs' where "DOMAIN" is the the active directory domain.

Othewise you could use "CN=Joe.Bloggs,DC=example,DC=com" instead of "DOMAIN\Joe.Bloggs"

perl -e 'map { $on=$_; s/\]/_/; rename($on, $_) or warn $!; } <*>;'
mecp () { scp "$@" ${SSH_CLIENT%% *}:Desktop/; }
2009-06-11 00:43:08
User: braino
Functions: scp
Tags: scp

Place in .bashrc and invoke like this: "mecp /path/to/file", and it will copy the specified file(s) back to the desktop of the host you're ssh'ing in from. To easily upload a file from the host you're ssh'ing in from use this:

ucp (){ scp ${SSH_CLIENT%% *}:Desktop/upload/* .; }

alias findstring="find . -type f -print | xargs grep $1"
$ i=(*);echo ${i[RANDOM%(${#i[@]}+1)]]}
2009-06-10 18:47:03
User: sputnick

An other way to run it ( playing a random file ending with avi, flv or mpeg ) from a specified dir and a specified type of extension :

making MOVIE array with a glob :

MOVIE=( /PATH/TO/MY/FAVORITE/MOVIES/*.{avi,flv,mpeg} )

playing the random file from a random key from the array

mplayer ${MOVIE[ RANDOM % ( ${#i[@]} + 1 ) ]]}

I use only globs and a bash array.

I use GNU bash, version 3.2.48

open .
tar czv Pictures | split -d -a 3 -b 16M - pics.tar.gz.
2009-06-09 19:48:01
User: asmoore82
Functions: split tar

Leave it to a proprietary software vendor to turn a cheap and easy parlor trick into a selling point. "Hey guys, why don't we turn our _collection of multiple files_ into a *collection of multiple files*!!" Extract the ^above with this:

cat pics.tar.gz.??? | tar xzv

^extract on any Unix - no need to install junkware!

(If you must make proprietary software, at least make it do something *new*)

if [ -e windows ]; then use 7-Zip

ffmpeg -i [source].avi -f mp4 -vcodec mpeg4 -b 250000 -s 480?320 -acodec aac -ar 24000 -ab 64 -ac 2 [destination].mp4
stty cbreak -echo; KEY=$(dd bs=1 count=1 2>/dev/null); stty -cbreak echo
2009-06-09 13:15:49
User: inof
Functions: dd stty

This shell snippet reads a single keypress from stdin and stores it in the $KEY variable.

You do NOT have to press the enter key!

The key is NOT echoed to stdout!

This is useful for implementing simple text menus in scripts and similar things.

x2vnc {-west|-east|-north|-south} computer-ip:display-number
2009-06-09 12:09:43
User: kellsens

This command use vnc to connect to another computer and emulate an dual-screen enviroment.

Example of use:

x2vnc -west

After this, if vnc server needs an password, will be prompt in the shell.

p.s.: sorry my english