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,488 results
rename .JPG .jpg *.JPG
2009-03-10 15:07:24
User: psytek
Functions: rename

This will change all files ending in .JPG to .jpg and will work with any file extension

ssh -fX <user>@<host> <program>
2009-03-10 15:02:35
User: prayer
Functions: ssh
Tags: ssh
ssh -X example.org xeyes

The SSH server configuration requires:

X11Forwarding yes # this is default in Debian

And it's convenient too:

Compression delayed

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.

echo -n $mypass | md5sum | awk {'print $1'}
2009-03-10 13:12:21
User: tororebelde
Functions: awk echo md5sum

This was useful to generate random passwords to some webpage users, using the sample code, inside a bash script

unalias ls
2009-03-10 11:23:31
Functions: unalias

Sometimes you have a situation where you cannot properly see the ls output when you are using a terminal w/a dark background. Usually bash has ls aliased to use colors, and you can easily get ls to use the default foreground color via simply unaliasing the command.

awk '{ for (f = 1; f <= NF; f++) a[NR, f] = $f } NF > nf { nf = NF } END { for (f = 1; f <= nf; f++) for (r = 1; r <= NR; r++) printf a[r, f] (r==NR ? RS : FS) }'
2009-03-10 05:35:22
User: MSBF
Functions: awk printf

works the same as R's t()

yes "text" | annoying_installer_program # "text" defaults to the letter y
set -o noclobber
2009-03-10 01:39:18
User: vududevil
Functions: set

Use set +o noclobber and you will be able to replace files again

sudo find / -iname "*.lproj" -and \! -iname "en*" -print0 | tee /dev/stderr | sudo xargs -0 rm -rfv
2009-03-09 22:08:45
User: asmoore82
Functions: find rm sudo tee xargs

This will get the job done in the most efficient way -

spawning only one `rm` process.

"On-the-fly" find data is displayed through `tee` and

you should have plenty of time to ctrl-c if needed before it's too late.

You may need to re-run this after major Software Updates.

To leave more languages in, add more ``-and \! -iname "lang*"'' statements:

sudo find / -iname "*.lproj" -and \! -iname "en*" -and \! -iname "spanish*" -print0 | tee /dev/stderr | sudo xargs -0 rm -rfv

**Edit: note the 2nd sudo near the end of the pipeline - this is necessary.

tar cf - . | (cd /new/dir; tar xvf -)
2009-03-09 20:30:34
User: jauderho
Functions: cd tar

Add z to the flags to enable compression.

mtree -c -K sha256digest -X mtree.exclude -p /path > host.mtree
wget -r ftp://user:pass@ftp.example.com
2009-03-09 19:39:30
User: movaxes
Functions: wget
Tags: wget

If the username includes an @ you can use this one:

wget -r --user=username_here --password=pass_here ftp://ftp.example.com

ls `echo $PATH | sed 's/:/ /g'`
2009-03-09 19:01:41
User: archlich
Functions: ls sed

If run in bash, this will display all executables that are in your current $PATH

find . -iname \*.mp3 -print0 | xargs -0 mp3gain -krd 6 && vorbisgain -rfs .
2009-03-09 18:11:35
User: Viaken
Functions: find xargs

Run this in the directory you store your music in.

mp3gain and vorbisgain applies the ReplayGain normalization routine to mp3 and ogg files (respectively) in a reversible way.

ReplayGain uses psychoacoustic analysis to make all files sound about the same loudness, so you don't get knocked out of your chair by loud songs after cranking up the volume on quieter ones.

nohup <command> 2> /dev/null > /dev/null &
2009-03-09 16:54:04
User: AmadeusZull
Functions: nohup

I'm sure this can be piped into another way. Please share!

for f in *;do mplayer $f;read $n;mv $f $n;done
2009-03-09 16:08:14
User: cobrajs272

I used this when I had a directory of movies from a camera. I wanted to watch a little of each movie, then rename it depending on what was in the movie. This did the trick for me.

for person in Alex Bruce Fred Kathy Vicki Victoria ; do say -v $person "Hello, my name is $person"; sleep 1; done
2009-03-09 15:42:13
User: haivu
Functions: sleep
Tags: Os X

Listen to different voices in the system--useful for picking the voice you like

mv file_name.extension ..
2009-03-09 15:35:58
User: takealeft
Functions: mv

cd into the directory that contains the file.

this is just the usual move command but shortcut'd.

say you wanted to move a photo img1.png from ~/photos/holidayphotos into the parent directory which is ~/photos

command would be:

~/photos/holidayphotos$ mv img1.png ..

I use Ubuntu so this'll work in debian but not sure what else.

export PS1='\n[\u@\h \! \w]\n\[\e[32m\]$ \[\e[0m\]'
2009-03-09 15:34:22
User: haivu
Functions: export
Tags: bash

I put that line in my .bash_profile (OS X) and .bashrc (Linux).

Here is a summary of what the \char means: n=new line, u=user name, h=host, !=history number, w=current work directory

The \[\e[32m\] sequence set the text to bright green and \[\e[0m\] returns to normal color.

For more information on what you can set in your bash prompt, google 'bash prompt'

find . -name .DS_Store -exec rm {} \;
2009-03-09 13:59:30
User: Svish
Functions: find rm
Tags: Os X

Recursively removes all those hidden .DS_Store folders starting in current working directory.

defaults write com.apple.Finder AppleShowAllFiles TRUE
2009-03-09 13:55:31
User: Svish
Functions: write
Tags: Os X

Swap TRUE with FALSE to turn it off again. Note: Finder must be relaunched afterwards to see the effect. For example like this:

killall Finder && open /System/Library/CoreServices/Finder.app
touch {1..10}.txt
2009-03-09 12:54:45
User: slaney
Functions: touch

Sometimes I need to create a directory of files to operate on to test out some commandlinefu I am cooking up. The main thing is the range ({1..N}) expansion.

svn diff ARGUMENTS_FOR_DIFF | source-highlight --out-format=esc --src-lang=diff
firefox -no-remote -P
2009-03-09 07:03:55
User: asmoore82

even when another instance is already open.

Great for testing purposes when you need

to be 2 people at once on the same site.

wget -S -O/dev/null "INSERT_URL_HERE" 2>&1 | grep Server
2009-03-09 06:54:54
User: asmoore82
Functions: grep wget

the good:

Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.4 with Suhosin-Patch

the bad:

Server: Microsoft-IIS/6.0

and the ugly:

Server: Apache/2.2.10 (Win32) mod_ssl/2.2.10 OpenSSL/0.9.8i PHP/5.2.6