Hide

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.

Hide

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:

Hide

News

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.
Hide

Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 11,491 results
while true; do X=$Y; sleep 1; Y=$(ifconfig eth0|grep RX\ bytes|awk '{ print $2 }'|cut -d : -f 2); echo "$(( Y-X )) bps"; done
function svnundopoint() { if [ -d .undo ]; then r=`svn info | grep Revision | cut -f 2 -d ' '` && t=`date +%F_%T` && f=${t}rev${r} && svn diff>.undo/$f && svn stat>.undo/stat_$f; else echo Missing .undo directory; fi }
2009-03-27 07:14:31
User: codeape
Functions: cut echo grep info
Tags: bash svn
2

Allows you to save progress without committing.

To revert to an undo point, svn revert then apply the undo point with patch.

svn revert -R . && patch -p0 < .undo/2009-03-27_08:08:11rev57

Similar: http://www.commandlinefu.com/commands/view/373/archive-all-files-containing-local-changes-svn

setarch i386 [command [args]]
2009-03-27 05:49:08
User: GinoMan2440
2

The above was done using the i386 flashplayer plugin, and was installed on a AMD64 machine running an AMD64 kernel and AMD64 programs. the resulting plugin install ultimately didn't work for swiftfox (but worked for iceweasel) without also covering it with a nspluginwrapper which took a bit of fenangaling to get to work (lots of apt-getting) but it is a nice feature to be able to trick installers that think you need i386 into running on a amd64, or at least attempting to run on amd64. Enjoy

eval "`dircolors -b`"
2009-03-27 05:37:04
User: isaacs
Functions: eval
Tags: ls
-2

If you put this in your .bashrc, you might also want to add this to make it use the colors by default:

alias ls="ls --color=auto"
svn status | egrep '^(M|A)' | egrep -o '[^MA\ ].*$'
2009-03-27 05:18:24
User: isaacs
Functions: egrep
Tags: svn
0

This is useful for piping to other commands, as well:

svn status | egrep '^(M|A)' | egrep -o '[^MA\ ].*$' | xargs $EDITOR
alias tree="tree -CAFa -I 'CVS|*.*.package|.svn|.git' --dirsfirst"
2009-03-27 05:13:39
User: isaacs
Functions: alias
Tags: tree
7

I got really tired of having tree always show me tons of .svn and .git stuff that I don't care about. With this alias, "tree" uses pretty colors, snazzy line graphics, and ignores any source control and package mumbojumbo. (Customize the *.*.package glob, of course.)

cat *.mpg > all.mpg
2009-03-27 04:49:18
User: smcpherson
Functions: cat
2

Good old cat & output redirection. Using this method you can combine all kinds of things - even mpeg files. My video camera makes a series of .mpeg files that are broken into 4gb chunks. Using this command I can easily join them together. Even better, combined with the cp command the files can be copied and joined in one step.

while true ; do scripts/bootstrap.py ; ./manage.py runserver ; done
2009-03-27 04:43:54
User: taurus
Functions: true
-3

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
-8

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
2

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
-3

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

echo !whammy

and

echo "!whammy"

both output:

-bash: !whammy: event not found

and this:

echo "\!whammy"

outputs:

\!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"'!'

outputs:

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
-1

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
2

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
3

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
3

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
1

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
2

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
-1

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
0

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
-10

Generate the iso from the disk, easily.

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