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,926 results
INPUT=<input_video> && ffmpeg -i "$INPUT" -vn -f wav - | oggenc -o ${INPUT%%.*}.ogg -
2009-05-19 07:57:43
User: DaveQB

Assumes you have ffmpeg and oggenc.

Similar to other scripts here, but this time outputting to Ogg Vorbis.

I added the variable assignment for a nice output name.

This is part of an interactive bash script I have with a few little multimedia tasks in it.


uuencode archive.tar.gz archive.tar.gz | mail -s "Emailing: archive.tar.gz" user@example.com
2009-05-19 07:17:37
Functions: mail uuencode

The uuencode utility will encode your file so that it can be sent as an attachment to an email. It is part of the sharutils package in RHEL/CentOS/Fedora.

mailx bar@foo.com -s "HTML Hello" -a "Content-Type: text/html" < body.htm
2009-05-19 04:49:26
User: ethanmiller
Functions: mailx
Tags: mail smtp html

Note, this works because smtp is running

ffmpeg -i filename.flv
2009-05-18 22:57:46
Tags: ffmpeg

I used an flv in my example, but it'll work on any file ffmpeg supports. It says it wants an output file, but it tells what you want to know without one.

for f in *.m4a; do ffmpeg -i "$f" "${f%.m4a}.flv"; done
2009-05-18 22:38:49
Tags: ffmpeg flv

This converts all m4a files in a dir to flv. You can just swap the m4a bit to anything else ffmpeg supports though, and it'll work.

for f in *.flv; do ffmpeg -y -i "$f" -f image2 -ss 10 -vframes 1 -an "${f%.flv}.jpg"; done
2009-05-18 22:34:59
Tags: ffmpeg jpg flv

This is handy for making screenshots of all your videos for referring to in your flv player.

ssh -i $PRIVATEKEY $HOST -C 'cd $SOURCE; tar -cz --numeric-owner .' | tee $DESTINATION/backup.tgz | tar -tz
2009-05-18 20:36:45
User: GeckoDH
Functions: ssh tar tee
PRIVATEKEY - Of course the full path to the private key \n HOST - The host where to get the backup \n SOURCE - The directory you wish to backup \n DESTINATION - The destination for the backup on your local machine
date -d2009-05-18 > /dev/null 2>&1 ; echo $?
2009-05-18 20:30:05
User: GeckoDH
Functions: date echo

Important to know: a valid date will return 0, otherwise 1!

killall -STOP -m firefox
2009-05-18 20:02:44
Functions: killall

Continue with:

killall -CONT -m firefox

Suspends all Firefox Threads. Results in Zero CPU load.

Useful when having 100+ Tabs open and you temporarily need the power elsewhere.

Be careful - might produce RACE CONDITIONS or LOCKUPS in other processes or FF itself.

matching is case sensitive.

transcode -i myvideo.avi -x mplayer="-sub myvideo.srt" -o myvideo_subtitled.avi -y xvid
2009-05-18 19:39:51
User: norby

It prints myvideo.srt subtitle files in myvideo.avi, saving it in myvideo_subtitled.avi

wget -H -r -nv --level=1 -k -p -erobots=off -np -N --exclude-domains=del.icio.us,doubleclick.net --exclude-directories=
rec -c 2 -r 44100 -s -t wav - | oggenc -q 5 --raw --raw-chan=2 --raw-rate=44100 --raw-bits=16 - > MyLiveRecording.ogg
2009-05-18 15:26:34
User: bohwaz

This will record the capture channel of your soundcard, directly encoded in Ogg Vorbis, in stereo at quality 5 (I'm using this to record live jam sessions from my line input). You can choose which device to capture (eg. line input, microphone or PCM output) with

alsamixer -V capture

You can do the same thing and live encode in MP3 or FLAC if you wish, just check FLAC and LAME man pages.

cd ../"$(ls -F ..|grep '/'|grep -B1 `basename $PWD`|head -n 1)"
2009-05-18 06:44:02
User: gwiener
Functions: cd

Based on linkinpark342 suggestion.

Sometimes you have to browse your way through a lot of sub-directories. This command cd to the previous sub-directory in alphabetical order. For example, if you have the directories "lectures/01-intro", "lectures/02-basic", "lectures/03-advanced" and so on, and your PWD is "02-basic", it jumps to "01-intro".

cd ../"$(ls -F ..|grep '/'|grep -A1 `basename $PWD`|tail -n 1)"
2009-05-18 06:41:37
User: gwiener
Functions: cd

Another version based on linkinpark342's contribution.

Sometimes you have to browse your way through a lot of sub-directories. This command cd to the next sub-directory in alphabetical order. For example, if you have the directories "lectures/01-intro", "lectures/02-basic", "lectures/03-advanced" and so on, and your PWD is "02-basic", it jumps to "03-advanced".

function autoCompleteHostname() { local hosts; local cur; hosts=($(awk '{print $1}' ~/.ssh/known_hosts | cut -d, -f1)); cur=${COMP_WORDS[COMP_CWORD]}; COMPREPLY=($(compgen -W '${hosts[@]}' -- $cur )) } complete -F autoCompleteHostname ssh
2009-05-17 23:12:34
User: sbisordi
Functions: awk cut

This is meant for the bash shell. Put this function in your .profile and you'll be able to use tab-completion for sshing any host which is in your known_hosts file. This assumes that your known_hosts file is located at ~/.ssh/known_hosts. The "complete" command should go on a separate line as such:

function autoCompleteHostname() {

local hosts=($(awk '{print $1}' ~/.ssh/known_hosts | cut -d, -f1));

local cur=${COMP_WORDS[COMP_CWORD]};

COMPREPLY=($(compgen -W '${hosts[@]}' -- $cur ))


complete -F autoCompleteHostname ssh

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

mencoder -ovc copy -nosound ./movie.mov -o ./movie_mute.mov
2009-05-17 11:56:22
User: angleto

create a copy of a video file without the audio tracs

find . -name \*.mp3 -printf "%C+ %h/%f\n" | sort -r | head -n20 | awk '{print "\""$2"\""}' | xargs -I {} cp {} ~/tmp
2009-05-17 07:06:10
User: bkinsey
Functions: awk cp find head sort xargs

Change ~/tmp to the destination directory, such as your mounted media. Change -n20 to whatever number of files to copy. It should quit when media is full. I use this to put my most recently downloaded podcasts onto my phone.

lsb_release -a
2009-05-17 02:49:18
User: Vasudev

Get the complete distro information from shell prompt like distributor ID,code name etc.

for d in `find .. -mindepth 1 -maxdepth 1 -type d | sort`; do if [[ `basename $d` > `basename $PWD` ]]; then cd $d; break; fi; done
2009-05-16 17:33:34
User: gwiener
Functions: cd

Sometimes you have to browse your way through a lot of sub-directories. This command cd to the next sub-directory in alphabetical order. For example, if you have the directories "lectures/01-intro", "lectures/02-basic", "lectures/03-advanced" and so on, and your PWD is "02-basic", it jumps to "03-advanced".

while true; do cat /usr/src/linux/kernel/signal.c > /dev/dsp; done
2009-05-16 14:44:57
Functions: cat

replace "/usr/src/linux/kernel/signal.c" with any file you want and listen to its output ! :P

you can also replace "cat" with "echo" or anything you can come up with

have fun :-}

find . -name '*.m4a' | xargs -I audiofile mplayer -ao pcm "audiofile" -ao pcm:file="audiofile.wav"
find /var -mount -ls -xdev | /usr/bin/sort -nr +6 | more
zpool create tank /path/to/file/a /path/to/file/b
2009-05-16 10:46:17
User: mnikhil
Tags: zfs zpool

This command creates an unmirrored pool using

files. While not recommended, a pool based on files can be

useful for experimental purposes.

zpool create tank mirror c0t0d0 c0t1d0 mirror c0t2d0 c0t3d0
2009-05-16 10:44:56
User: mnikhil
Tags: zfs zpool

command creates a pool with two mirrors, where each mirror contains two disks.