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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



All commands from sorted by
Terminal - All commands - 12,421 results
while true ; do scripts/bootstrap.py ; ./manage.py runserver ; done
2009-03-27 04:43:54
User: taurus
Functions: true

I wrote a script called bootstrap.py to delete the database, then load a new database with initial values. With this single-line shell loop, when I need to make a schema change (which happens often in the early stages of some projects), I hit ctrl-C to stop the running Django server, then watch bootstrap.py do its thing, then watch the server restart.

mv `find .zip ./` .
2009-03-27 04:42:48
User: smcpherson
Functions: mv
Tags: find

This is useful if you have a collection of files in folders (for example, a bunch of .zip files that are contained in folders) and you want to move them all to a common folder.

ffmpeg -i "/path/to/file.mp4" "/path/to/file.avi"
mencoder "/path/to/file.wmv" -ofps 23.976 -ovc lavc -oac copy -o "/path/to/file.avi"
git log --pretty=oneline
2009-03-27 04:16:43
User: smcpherson

Assuming you are working within a git repository, you can run the above command & see what has changed in reverse chronological order, with one commit per line. Other formatting variations to 'oneline' include 'short', 'medium', 'full', 'fuller', 'email' or 'raw'.

echo '!'whammy
2009-03-26 23:34:33
User: sudopeople
Functions: echo
Tags: literal bang

Seems obvious, but other seemingly simple ways to use it don't work:

echo !whammy


echo "!whammy"

both output:

-bash: !whammy: event not found

and this:

echo "\!whammy"



with the slash :(

you can also do any combinations of quotes for a complex string:

echo "It's great to be able to use a bang ("'!'") in a command"'!'


It's great to be able to use a bang (!) in a command!
curl -o <bibliography> "http://www.citeulike.org/bibtex/user/<user>"
2009-03-26 23:08:14
User: qubyte

I love CiteULike. It makes keeping a bibtex library easy and keeps all my papers in one place. However, it can be a pain when I add new entries and have to go through the procedure for downloading the new version in my browser, so I made this to grab it for me! I actually pipe it directly into a couple of SED one liners to tidy it up a bit too. Extremely useful, especially if you make a custom BibTeX script that does this first. That way you can sort a fresh BibTeX file for each new paper with no faf.

To use just replace with your CiteULike user name. It doesn't download entries that you've hidden but I don't use that feature anyway.

telnet towel.blinkenlights.nl
watch -n 10 "wget -q http://www.brillig.com/debt_clock -O - | grep debtiv.gif | sed -e 's/.*ALT=\"//' -e 's/\".*//' -e 's/ //g'"
2009-03-26 19:32:57
User: matrtsmiller
Functions: watch

The idea was originally stolen from Linux Journal. 'wget' pulls the debt clock and 'sed' reformats it for general consumption. Prefacing the command with 'watch' simply sets an interval - in this case every 10 seconds.

while [ 1 ]; do echo -n "`date +%F_%T`" ; vmstat 1 2 | tail -1 ; sleep 4; done
2009-03-26 19:16:55
User: plasticboy
Functions: echo sleep tail vmstat

See man vmstat for information about the statistics.

This does the same thing without the timestamp:

vmstat 5
tail -f logfile.log | cut -b 1-80
2009-03-26 18:41:57
User: plasticboy
Functions: cut tail
Tags: tail log

This truncates any lines longer than 80 characters. Also useful for looking at different parts of the line, e.g. cut -b 50-100 shows columns 50 through 100.

find . -name 'junkfiles-*' -print0 | xargs -0 rm
2009-03-26 15:38:42
User: kancer
Functions: find xargs
Tags: find xargs print rm

Can be used for other commands as well, replace rm with ls.

It is easy to make this shorter but if the filenames involved have spaces, you will need to do use find's "-print0" option in conjunction with xargs's "-0" option. Otherwise the shell that xargs uses to execute the "rm" command line will treat the space as a token separator, thereby treating the name as two (or more) names.

watch -n1 --differences cat /proc/meminfo
python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"
slave start; SELECT MASTER_POS_WAIT('master.000088','8145654'); slave stop;
2009-03-26 14:11:43
User: slim

say you want to reinitialize the slave database without resetting the master positions. You stop the slave, dump the master database with --master-data=2 then execute the command on the slave and wait for it to stop at the exact position of the dump. reinit the slave db and start the slave. enjoy.

scrot -e 'mv $f \$HOME/shots/; sitecopy -u shots; echo "\$BASE/$f" | xsel -i; feh `xsel -o`'
2009-03-26 12:08:39
User: penpen
Functions: echo

Here $HOME/shots must exist and have appropriate access rights and sitecopy must be correctly set up to upload new screen shots to the remote site.

Example .sitecopyrc (for illustration purposes only)

site shots

server ftp.example.com

username user

password antabakadesuka

local /home/penpen/shots

remote public_html/shots

permissions ignore

The command uses scrot to create a screen shot, moves it to the screen shot directory, uploads it using screen uses xsel to copy the URL to the paste buffer (so that you can paste it with a middle click) and finally uses feh to display a preview of the screen shot.

Note that $BASE stands for the base URL for the screen shots on the remote server, replace it by the actual location; in the example http://www.example.com/~user/shots would be fitting.

Assign this command to a key combination or an icon in whatever panel you use.

scrot -e 'mv $f \$HOME/public_html/shots/; echo "http://\$HOSTNAME/~\$USER/shots/$f" | xsel -i; feh `xsel -o`'
2009-03-26 11:32:09
User: penpen
Functions: echo

A web server using $HOME/public_html as user directory is required, $HOME/public_html/shots must exist and have appropriate access rights and $HOSTNAME must be known to and accessible from the outside world.

The command uses scrot to create a screen shot, moves it to the screen shot directory, uses xsel to copy the URL to the paste buffer (so that you can paste it with a middle click) and finally uses feh to display a preview of the screen shot.

Assign this command to a key combination or an icon in whatever panel you use.

cat /dev/cdrom > ~/mydisk.iso
2009-03-26 05:54:41
User: sata
Functions: cat
Tags: Linux

Generate the iso from the disk, easily.

same as "dd if=/dev/cdrom of=~/mydisk.iso"

unzip \*.zip
2009-03-26 02:36:28
User: tiagofischer
Tags: unzip

"unzip *.zip" doesn't work as expected, because unzip handle wildcards in a different way.

You just need to escape the wildcard or do in another way:

for f in *.zip; do unzip "$f"; done
xclip -o > /tmp/spell.tmp; aspell check /tmp/spell.tmp ; cat /tmp/spell.tmp | xclip
2009-03-26 00:49:59
User: alperyilmaz
Functions: cat

xclip -o > /tmp/spell.tmp # Copy clipboard contents to a temp file

aspell check /tmp/spell.tmp # Run aspell on that file

cat /tmp/spell.tmp | xclip # Copy the results back to the clipboard, so that you can paste the corrected text

I'm not sure xclip is installed in most distributions. If not, you can install x11-apps package

% screen -r someuser/
2009-03-25 23:59:38
User: totoro
Functions: screen

If you enable multiuser, then you can permit others to share your screen session. The following conditions apply:

1. screen must be suid root;

2. "multiuser on" must be configured in ~/.screenrc;

3. control the others user(s) access with "aclchg":

# ----- from ~/.screenrc-users -----

aclchg someuser +rx "#?" #enable r/o access to "someuser"

aclchg someuser -x "#,at,aclchg,acladd,acldel,quit" # don't allow these

aclchg otheruser +rwx "#?" # enable r/w access to "otheruser"

aclchg otheruser -x "#,at,aclchg,acladd,acldel,quit" # don't allow them to use these commands

# -----

After doing this (once), you start your session with:

$ screen

Then, the other user can join your terminal session(s) with youruserid:

$ screen -r youruserid/

Note: the trailing "/" is required.

Multiple users can share the same screen simultaneously, each with independent access controlled precisely with "aclchg" in the ~/.screenrc file.

I use the following setup:

# ~/.screenrc-base

# default screenrc on any host

source $HOME/.screenrc-base

source $HOME/.screenrc-$HOST

source $HOME/.screenrc-users

# -----

Then, the base configurations are in ~/.screenrc-base; the host-specific configurations are in ~/.screenrc-$HOST, and the user configurations are in ~/.screenrc-users.

The host-specific .screenrc file might contain some host-specific screen commands; e.g.:

# ~/.screen-myhost

# -----

screen -t 'anywhere' /bin/tcsh

screen -t 'anywhere1' /bin/tcsh

# ----

The .screenrc-base contains:

# ~/.screenrc-base

## I find typing ^a (Control-a) awkward. So I set the escape key to CTRL-j instead of a.

escape ^Jj

termcapinfo xterm* [email protected]:[email protected]:

autodetach on

zombie kr

verbose on

multiuser on

function fork () { tf=$(tempfile -d /tmp -p $1.);echo -n "$tf "; [email protected] &>$tf& }
2009-03-25 23:33:54

This function runs a program in the background, and logs all output to an automatically created logfile. That way, you can still get at the output without it clogging up your terminal.


Throw fork() and this:

for prog in firefox kate konqueror ;do alias $prog="fork $prog";done

into your bashrc, so that they'll automatically run out of the way.

function nuke() { if [ $(whoami) != "root" ] ; then for x in [email protected]; do sudo apt-get autoremove --purge $x; done; else for x in [email protected]; do apt-get autoremove --purge $x; done; fi }
2009-03-25 23:21:21
User: ruinbox
Functions: sudo
Tags: sudo apt-get

You can't stand programs x, y, and z. Remove all trace of their existence by adding this function to your config. It will remove the cruft, the settings, and such and such. This function doesn't even give a damn about you trying to remove programs that don't exist: it'll just for loop to the next one on your hit list.

nc -l 8000
2009-03-25 23:09:38
User: penpen
Tags: Linux unix WWW

Have netcat listen on port 8000, point browser to http://localhost:8000/ and you see the information sent. netcat terminates as soon as your browser disconnects.

I tested this command on my Fedora box but linuxrawkstar pointed out that he needs to use

nc -l -p 8000

instead. This depends on the netcat version you use. The additional '-p' is required by GNU netcat that for example is used by Debian but not by the OpenBSD netcat port used by my Fedora system.

watch -n 1 :
2009-03-25 23:00:28
User: penpen
Functions: watch
Tags: Linux unix

'watch' repeatedly (default every 2 seconds, -n 1 => every second) runs a command (here ':', a shorthand for 'true'), displays the output (here nothing) and the date and time of the last run.

I thought it to be obvious but it seemingly is not: to exit use Ctrl-C.