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,618 results
urpmi --auto-update --force # apply all pending updates (Mandriva Linux)
2009-03-28 14:59:26
User: mpb

Update a Mandriva Linux system with any pending updates.

This command needs to be run with root privilege.

Using the "--force" option answers "yes" to any interactive prompts

thus allowing the updates to be left unattended to completion.

NB if there is an update for glibc and/or a new kernel then the system

would need to be rebooted for these to take effect.

A prerequisite for running "urpmi --auto-update" is to have correctly defined

urpmi media sources (which can be done by visiting http://easyurpmi.zarb.org/).

If there are no new updates the the message "Packages are up to date" is shown.

awk '/start_pattern/,/stop_pattern/' file.txt
2009-03-28 14:28:59
User: atoponce
Functions: awk

I find this terribly useful for grepping through a file, looking for just a block of text. There's "grep -A # pattern file.txt" to see a specific number of lines following your pattern, but what if you want to see the whole block? Say, the output of "dmidecode" (as root):

dmidecode | awk '/Battery/,/^$/'

Will show me everything following the battery block up to the next block of text. Again, I find this extremely useful when I want to see whole blocks of text based on a pattern, and I don't care to see the rest of the data in output. This could be used against the '/etc/securetty/user' file on Unix to find the block of a specific user. It could be used against VirtualHosts or Directories on Apache to find specific definitions. The scenarios go on for any text formatted in a block fashion. Very handy.

mount.gmailfs none /mount/path/ [-o username=USERNAME[,password=PASSWORD][,fsname=VOLUME]] [-p]
2009-03-28 13:00:47
User: cammarin
Functions: mount
Tags: gmailfs fuse

Packages: gmailfs fuse-utils libfuse2 gvfs-fuse

Config files: /etc/gmailfs/gmailfs.conf; ~/.gmailfs.conf (make a copy from the another one)


fusermount -u /mount/path/

/etc/fstab (Optional):

none /mount/path/ gmailfs

noauto,user[,username=USERNAME,password=PASSWORD,fsname=VOLUME] 0 0


- The options between [] are optional since they already setuped on the config files.

- The '-p' flag shows a prompt for the password entry.

- It's necessary to add the user to the 'fuse' group. You can do that with:

sudo chgrp fuse /dev/fuse


sudo usermod -a -G fuse USER

- The volume name is not needed but highly recommended to avoid file corruption. Also choose a non-trivial name.

- Google doesn't approve the use of Gmail account other than e-mail purposes. So, I recommend the creation of a new account for this.

host -la domain.com
2009-03-28 12:15:16
Functions: host

Perform a dns zone transfer (if is allowed on target dns server) and print result.

2009-03-28 11:43:21
User: mpb

See: "man pwgen" for full details.

Some Linux distros may not have pwgen included in the base distribution

so you maye have to install it (eg in Mandriva Linux: "urpmi pwgen").

sudo firefox -install-global-extension /path/to/add-on
2009-03-28 11:11:12
User: cammarin
Functions: sudo
Tags: firefox

To install a theme use:

sudo firefox -install-global-theme /path/to/theme

You can get the .xpi or .jar file from the versions history on the add-on/theme page.

NOTE: may not work in your system (Debian-based is an example).

mplayer -vo aa <video file>
wget -c -t 1 --load-cookies ~/.cookies/rapidshare <URL>
2009-03-28 09:13:35
User: cammarin
Functions: wget

The download content part.

NOTE: the '-c' seems to not work very well and the download stuck at 99% sometimes. Just finish wget with no problem. Also, the download may restart after complete. You can also cancel. I don't know if it is a wget or Rapidshare glitch since I don't have problems with Megaupload, for example.

UPDATE: as pointed by roebek the restart glitch can be solved by the "-t 1" option. Thanks a lot.

wget --save-cookies ~/.cookies/rapidshare --post-data "login=USERNAME&password=PASSWORD" -O - https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi > /dev/null
2009-03-28 09:12:02
User: cammarin
Functions: wget

In order to do that, first you need to save a cookie file with your account info. These commands do it (maybe you need to create the '.cookies' dir before). Also, you need to check the "Direct downloads" option on the Premium Zone >> Settings tab.

You need to do this once (as long you maintain the file or your Rapidshare Premium account).

apg -a 0 -n 10
2009-03-28 02:28:19
User: acirulli
Tags: vim vi

Within vi allow to empty a text file in one shot

2009-03-28 00:18:39
User: mpb

The vi key sequence !}command will send the file contents from the cursor

to the next blank line as STDOUT to the command specified

and replace that sequence of file lines with the output of the command.

For example: sorting a block of data - !}sort

The sequence !{command will do the same but "upwards" (from the current position towards the start of the file.

chmod +x FILES
sudo chmod -R g=u-w,g+X *
ls -Sl * | head
2009-03-27 23:20:32
User: colinpj
Functions: ls

head by default displays first ten lines of its output. Use 'head -nXX' to display the XX largest files

base64 -d <<< aHR0cDovL3d3dy50d2l0dGVyc2hlZXAuY29tL3Jlc3VsdHMucGhwP3U9Y29tbWFuZGxpbmVmdQo=
2009-03-27 23:20:23
User: stu

apart from not being generalisable to all shells, `Y <<< X` seems nicer to me than `echo X | Y`, e.g.

&lt;&lt;&lt; lol cat;

it reads easier, you type less, and it also looks cool

kill -9 $$
2009-03-27 23:13:53
User: stu
Functions: kill
Tags: history exit

this exits bash without saving the history. unlike explicitly disabling the history in some way, this works anywhere, and it works if you decide *after* issuing the command you don't want logged, that you don't want it logged

... $$ ( or ${$} ) is the pid of the current bash instance

this also works perfectly in shells that don't have $$ if you do something like

kill -9 `readlink /proc/self`
netstat -atn | awk ' /tcp/ {printf("%s\n",substr($4,index($4,":")+1,length($4) )) }' | sed -e "s/://g" | sort -rnu | awk '{array [$1] = $1} END {i=32768; again=1; while (again == 1) {if (array[i] == i) {i=i+1} else {print i; again=0}}}'
2009-03-27 20:38:43
User: mpb
Functions: awk netstat sed sort

Some commands (such as netcat) have a port option but how can you know which ports are unused?

service --status-all | grep running
2009-03-27 19:53:30
User: Williebee
Functions: grep

A quick way to list services running

2009-03-27 18:56:36
User: jnash

Python comments begin with a #. Modify to suit other languages.

Other uses: Instead of m0 use m$ for end of file or d for deleting all comments.

perl -pi -e 's/foo/bar/g' $(grep -rl foo ./*)
2009-03-27 17:21:35
User: dopeman
Functions: grep perl
Tags: perl

This command will replace all instances of 'foo' with 'bar' in all files in the current working directory and any sub-directories.

perl -pi -e 's/foo/bar/g' $(grep -l foo ./*)
2009-03-27 17:18:08
User: dopeman
Functions: grep perl

This command will replace all instances of 'foo' with 'bar' in all files in the current working directory.

rename 's/.*/[it]$&/' *.pdf
iptables -F && iptables -X && iptables -P INPUT ACCEPT && iptables -OUTPUT ACCEPT
2009-03-27 15:03:54
User: lme
Functions: iptables
Tags: Linux iptables

This turns your iptables packet filter to a "Allow any from any to any" filter, so you can rule out any filtering issues when you have a problem to enable a connection from or to your host.

To re-enable it, run /etc/init.d/iptables restart

vlc -vvv http://mafreebox.freebox.fr/freeboxtv/playlist.m3u --sout '#transcode{vcodec=mp2v,vb=384,scale=0.5,acodec=vorbis,ab=48,channels=1}:standard{access=http,mux=ogg,url=:12345}' -I ncurses 2> /dev/null
2009-03-27 14:29:27
User: pronoiaque

You can watch channels of your freebox, everywhere. With " vlc http://your-ip:12345 " on the client and ncurses vlc interface on the host. et voila