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.


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:



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.




All commands from sorted by
Terminal - All commands - 11,998 results
grep --color=always -nr 'setLevel' --include=*py | less -SRqg
convert infile.png \( +clone -channel GB -evaluate set 0 +channel \) +append -region 50%x100% -channel R -evaluate set 0 +channel outfile.png
2013-04-30 20:46:02
User: bugmenot
Functions: set

Converts red-cyan 3D anaglyphs to side-by-side format viewable by crossing your eyes. Useful for people who don't have 3D glasses or prefer not to use one.

echo "q+werty%3D%2F%3B" | php -r "echo urldecode(file_get_contents('php://stdin'));"
2013-07-17 11:37:36
User: kartikssj
Functions: echo
Tags: urldecod PHP

Using PHP shell to URL decode a string.

perl -nle 'print length,"\t",$_ if length > 37' < /path/to/input/file
find . -name "*.html" -exec grep -l 'string' {} \;
2010-04-12 20:47:25
User: rexington
Functions: find grep

This will search for "string" in all files under the given path "." and provide a listing of the files with their relative locations.

echo Good $(i=`date +%H` ; if [ $i -lt 12 ] ; then echo morning ; else if [ $i -lt 15 ] ; then echo afternoon ; else echo evening ; fi ; fi)
2010-09-23 09:50:13
User: jyro
Functions: echo
Tags: date

Saves all the "cut" hacks

perl -le 'print time()'
svnradd() { for i in $1/*;do if [ -e "$i" ];then if [ -d "$i" ];then svn add $i;svnradd $i;else svn add $i;fi; fi;done }
2011-02-16 03:33:57
User: lkjoel

This will recursively add files/directories in SVN.


svnradd yourfile


svnradd yourdirectory


svn commit

Notice: It might not work properly, and not all files could get added.

Since there is a limit on characters, I couldn't add failure/success notices.

If you want failure/success notices, download Terminal Enhancements (http://tenhancements.tk/ )

It is included on Base Features

psbook file.ps | psnup -2 -l -m0.5cm | pstops '2:0,1U(210mm,297mm)' > file.booklet.ps
2011-03-24 08:56:32
User: theist

'booklet' is the name they'll give it in fineprint windows alternative. It's a postscript file prepared to be printed dual side, one page per sheet, and, once finished you can place staples in the middle of the print, fold, and read it like a book.

mencoder input.m2ts -oac mp3lame -lameopts cbr:br=128 -ofps 24 -vf harddup -vf scale=1280:720 -ovc xvid -xvidencopts fixed_quant=3 -o output.xvid.lamp.avi
grep -c '^$' /proc/cpuinfo
2011-10-09 14:05:14
User: _john
Functions: grep

All Linux Systems I try also have an empty line per cpu in /proc/cpuinfo... little shorter then...

pgrep -f 'process.*argument.*'
du -k | sort -n | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf ("%6.1f\t%s\t%25s %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"x (1.5*$l),$2);}' | more
2012-02-07 15:49:19
User: Q_Element
Functions: du perl printf sort

This one line Perl script will display the smallest to the largest files sizes in all directories on a server.

git for-each-ref --sort=-committerdate --format="%1B[32m%(committerdate:iso8601) %1B[34m%(committerdate:relative) %1B[0;m%(refname:short)" refs/heads/
2013-03-11 20:48:25
User: mstormo
Tags: git branches

Full output in one single git command, no pipes nor other process invocations.

Will also work under cmd on Windows, with MSysGit, and can be aliased, simply add


branch-rel = "for-each-ref --sort=-committerdate --format='%1B[32m%(committerdate:iso8601) %1B[34m%(committerdate:relative) %1B[0;m%(refname:short)' refs/heads/"

to your .gitconfig file.

find ./ -type f | sed "s:[\ \',\"]:\\\&:g" | xargs md5sum
2013-07-17 18:54:14
User: crazedsanity
Functions: find sed xargs

Recursively list all files in the current directory & get their md5sum, even if the filename has bad characters.

project=YOURPROJECTHERE; package=YOURPACKAGEHERE; osc signkey --extend $project; osc rebuildpac project package
2013-09-27 07:49:41


This is pretty simple but every time I forget how to do it, so let's stick it here.

mogrify -resize 852x480 ./*.png
2013-12-24 12:42:06
User: evilsoup
Tags: ImageMagick

Requires ImageMagick to be installed; mogrify is the lesser-known sibling to convert -- it overwrites your original images, but allows you to work on batches of files without resorting to a loop.

dir=${PWD##*/}; rename "s/`ls -b1 | head -n1 | sed 's/.\{4\}$//'`/$dir/" -v *
2014-07-08 03:20:04
User: codycook
Functions: dir rename

I use this on Debian to rename files that exist in directories but do not have the year in the file name. The directory has the year but the files inside don't.

How I explain how this runs:

The dir variable grabs the name of the folder.

Using rename, substitute the name of the first file and remove the extension, then rename it to the directory name.

To test this before you run it, change -v to -vn.

find -type f -exec ffmpeg -i "{}" "{}".mp3 \;
slice="-rw-r--r-- "; ls -l | cut -c $(echo "$slice" | wc -c)-
sed 's/.*/ /'
2010-02-11 17:45:56
User: putnamhill
Functions: sed
Tags: sed

The first version printed:

tr: empty string2

The second version printed:

sed: -i may not be used with stdin

Maybe I misunderstood the orginal problem.

cobbler repo edit --name=Epel-i386 --environment="http_proxy="
2010-05-11 13:52:43
User: w00binda

This is the command to configure "cobbler reposync" to use a specific proxy setting to mirror locally the content of a specific remote repository.

find * ! -name abc -delete
imap <leader>r <C-r>=system('echo "$(($RANDOM % 100))"')<cr>
2010-10-24 00:37:44
User: voyeg3r

This mapping function is called RANDOM bash and enter a number between 1 and 100

yes 'clear;printf "`date`\n" | figlet -f starwars | boxes;sleep 1' | sh
2011-02-16 03:58:19
User: lkjoel
Functions: printf sleep yes

This is a different version from my original command: Console clock -- Beautiful (http://www.commandlinefu.com/commands/view/7902/console-clock-beautiful )

This one uses Boxes and Figlet.

To install the dependencies on Ubuntu, type in:

sudo apt-get install boxes figlet

To install the dependencies on Debian, type in:

aptitude install boxes figlet