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,848 results
netstat -taupe
2009-05-25 12:46:38
User: farwarx
Functions: netstat

Affiche des infos detaillees sur vos connexions reseaux.

Port en ?coute, protocole, paquets, adresses, ustilisateur, PID etc...

mplayer -vo caca foo.avi
2009-05-25 09:29:24
User: farwarx

Permet de lire une video dans une console, meme sans interface graphique.

Interet limite, mais a connaitre au cas ou.

mv $1 $2 && ln -s $2/$(basename $1) $(dirname $1)
sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e
2009-05-25 05:37:44
User: mohan43u
Functions: echo sed xargs
echo "http%3A%2F%2Fwww.google.com" | sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e


Works under bash on linux. just alter the '-e' option to its corresponding equivalence in your system to execute escape characters correctly.

mplayer -af scaletempo -speed 1.5 file.avi
2009-05-24 08:06:28
User: elementa13

Pitch-correct play speed with mplayer. You can also use [] and {} keys to change play speed on-the-fly.

ffmpeg -i source_movie.flv -vcodec mpeg2video target_video.m2v -acodec copy target_audio.mp3
2009-05-23 23:52:51
User: dcabanis

rips the audio and video stream of a movie. The two streams are stored separately.

ffmpeg -i source_audio.mp3 -itsoffset 00:00:10.2 -i source_video.m2v target_video.flv
2009-05-23 23:47:41
User: dcabanis

This assumes that there is a 10.2 sec delay between the video and the audio (delayed).

To extract the original video into a audio and video composites look at the command on extracting audio and video from a movie

ffmpeg -i mymovie.mpg -ar 22050 -acodec libmp3lame -ab 32K -r 25 -s 320x240 -vcodec flv mytarget.flv
2009-05-23 23:39:46
User: dcabanis

Takes an mpeg video and coverts it to a youtube compatible flv file.

The -r 25 sets the frame rate for PAL, for NTSC use 29.97

ffmpeg -i source.flv -vn acodec copy destination.mp3
2009-05-23 23:34:32
User: dcabanis

-vn removes tha video content, the copy option tells ffmpeg to use the same codec for generating the output

lame -h -V 6 track9.wav track9.mp3
2009-05-23 23:27:20
User: dcabanis

The quality ranges between 0 to 9, with the smaller number indicates a higher quality file but bigger too.

mplayer -fs cdda://9 -ao pcm:file=track9.wav
2009-05-23 23:23:45
User: dcabanis

Using mplayer to extract audio file from a CD

diff -uw <(fmt -1 {file1, file2})
2009-05-23 03:11:08
User: sunny256
Functions: diff fmt
Tags: bash diff

It can be hard to spot differences in reformatted files, because of all the diff noise created by word wrapped lines. This command removes all the noise and performs a word-by-word diff. To ignore empty lines, add -B to the diff command. Also, if this is something you do often, you might want to check out the wdiff(1) program.

Type "c-a b" in gnu screen after updating your .screenrc (See Description below).
2009-05-23 02:10:12
User: deeelwy
Functions: screen

This command will let you just type c-a b (which means press 'ctrl' then 'a' then 'b'), and screen will save your copy buffer to /tmp/screen-exchange, and then execute xsel to copy the contents of that file into the system's X clipboard.

1. Install Conrad Parker's xsel from http://www.vergenet.net/~conrad/software/xsel/

2. Add these lines to your .screenrc

# Add cool line to make copying to x clipboard possible.

# This binds C-a b to copy screen's copy buffer to the system clipboard.

bind b eval writebuf 'exec /bin/sh -c "xsel -i -b < /tmp/screen-exchange"' 'exec /bin/sh -c "killall xsel"'

3. Restart screen.

4. Test it by typing c-a [ to enter copy mode.

5. Select some text using vi movement keys (h, j, k, l, etc...) and starting your selection by hitting the space bar, moving with vi movement keys, and then ending your selection with the space bar.

6. Type C-a b, and screen will use xsel to copy your screen copy buffer to the system's X clipboard buffer.

7. Then you can paste the screen copy buffer into any X program.

Note: If you're using Mac OSX, you can use pbcopy instead of xsel.

Also Note: The second exec in the .screenrc file, which runs killall on xsel, is necessary, because even when you redirect a file to xsel, xsel waits for you to press ctrl-c to kill it, and have it stop waiting for more input. Since xsel forces screen to wait, and I don't want to press ctrl-c, I send the equivalent of ctrl-c with killall causing xsel to write /tmp/screen-exchange to the X clipboard, and then exit. It's a hack, but it works. If you know how to get this to work without a lame hack leave a comment explaining how.

cpp /usr/include/stdio.h | grep -v '^#' | grep -v '^$' | less
2009-05-22 22:40:25
User: mohan43u
Functions: cpp grep

will display typedefs, structs, unions and functions declared in 'stdio.h'(checkout _IO_FILE structure). It will be helpful if we want to know what a particular header file will offer to us. Command 'cpp' is GNU's C Preprocessor.

su -c "truecrypt --non-interactive truecrypt-file cryptshare -p PASSWORD"
2009-05-22 21:11:29
User: tatwright
Functions: su

This is useful for use in scripts.

Note that this will leak your password to ps, so this shouldn't be used on shared machines. Use key files for this

scanimage -d mustek_usb --resolution 100 --mode Color > image.pnm
2009-05-22 14:00:05
User: Giancarlo
Functions: scanimage

you have to replace "mustek_usb" with the scanner found by `scanimage -l`

lame --mp3input -m m --resample 24 input.mp3
2009-05-22 13:58:03
User: Giancarlo

Useful if you have to put some mp3 files into mobile devices (ie mobile phones with no much memory)

ffmpeg -i input.flv -f mp3 -vn -acodec copy ouput.mp3
rm -rf `find -maxdepth 1 -mindepth 1 -mtime +7`
2009-05-22 11:46:57
User: tatwright
Functions: rm

This is useful for command line 'recycle bins' and such like

sudo dmidecode -t 5,16
tar -tf file.tar | tar -T - -uf file.tar
2009-05-22 00:28:13
Functions: tar

This will update the tarball, adding files that have changed since the last update.

This assumes that the tarball is in the same directory as the files being archived.

N.B. This command can't be used on compressed tarballs.

N.B. This will add the updated files to the tarball, so that the tarball will have two versions of each file. This will make the tarball larger, but doesn't have any other significant effect.

alias setvol='aumix -v'
2009-05-21 22:39:40
User: b2e
Functions: alias

If you're addicted to command-line solutions of ordinary actions or if you just want to set your volume from bed via mobile phone SSH, you can set this alias and use it as

setvol 50

for setting volume on 50% gain

Works only with ALSA, tested on Ubuntu 8.10. Give me some info about your experience.

TIP: Try aslo command "mute" to toggle mute/unmute sound. But I don't know if this works on all distros.

killall -s 9 krunner_lock
2009-05-21 22:29:06
User: b2e
Functions: killall

With this you can unlock your KDE4 session via SSH, via mobile phone SSH or e. g. scheduled task in crontab (without asking password). Useful when you need to grant somebody access to your locked profile remotely.

Create an alias (e. g. as "unlock") and use with remote KDE4 lock.

This works only on KDE4 boxes because KDE 3 is using utility with another name.

Tested on Kubuntu 8.10.

DISPLAY=:0 /usr/lib/kde4/libexec/krunner_lock --forcelock >/dev/null 2>&1 &
2009-05-21 22:19:16
User: b2e

Forgot to lock your computer? Want to lock it via SSH or mobile phone or use it for scheduled lock?

TIP: Make a alias for this (e. g. as "lock").

I found some howtos for ugly X11 lock, but this will use regular KDE locking utility.

Note that KDE 3 is using utility with another name (I guess with the same argument --forcelock)

Tested on Kubuntu 8.10.

Stay tuned for remote unlock.