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,858 results
find cvsdir -name Root -exec sed -i 's/oldserver/newserver/' {} \;
2009-02-19 04:31:13
User: mulad
Functions: find sed
0

If your CVS server has moved, here's a way to update your CVS Root files throughout your code tree without checking out a new copy of your files.

apt-get () { [ "$1" = source ] && (command apt-get "$@";true) || sudo apt-get "$@" }
2009-02-19 04:17:24
User: mulad
Functions: apt command sudo
1

An apt-get wrapper function which will run the command via sudo, but will run it normally if you're only downloading source files.

This was a bit of an excuse to show off the framework of

cmd && echo true || echo false

...but as you can see, you must be careful about what is in the "true" block to make sure it executes without error, otherwise the "false" block will be executed.

To allow the apt-get return code to pass through, you need to use a more normal if/else block:

apt-get () { if [ "$1" = source ]; then command apt-get "$@"; else sudo apt-get "$@"; fi }
wget -r -l1 -H -t1 -nd -N -np -A.mp3 -erobots=off -i ~/sourceurls.txt
2009-02-19 03:52:47
User: tomhiggins
Functions: wget
1

This was gotten from http://www.veen.com/jeff/archives/000573.html. The line will grab all the mp3 files on the urls listed in text file sourceurls.txt (one url per line) . A much more complete breakdown of the line can be found at the web site mentioned above.

find . -name .svn | xargs rm -rf
tar ztf tar-lacking-subdirectory.tar.gz | xargs rm
2009-02-19 00:34:09
User: mulad
Functions: tar xargs
2

These days, most software distributed in tar files will just contain a directory at the top level, but some tar files don't have this and can leave you with a mess of files in the current folder if you blindly execute

tar zxvf something.tar.gz

This command can help you clean up after such a mistake. However, note that this has the potential to do bad things if someone has been *really* nasty with filenames.

trap "echo \"$0 process $$ killed on $(date).\"; exit " HUP INT QUIT ABRT TERM STOP
for f in *.ogg; do vorbiscomment -l "$f" | sed 's/peter gabriel/Peter Gabriel/' | vorbiscomment -w "$f"; done
2009-02-18 23:54:01
User: mulad
Functions: sed
1

The "vorbiscomment" utility lets you update information such as artist names and song and album tags in an Ogg Vorbis file. You can use this command to fix any mistakes that were made when ripping an album.

psg () { ps auxwww | egrep "$1|PID" | grep -v grep }
2009-02-18 23:37:35
User: mulad
Functions: egrep grep ps
1

Yet another ps grep function, but this one includes the column headings.

while true; do read i; echo $[$i]; done
2009-02-18 23:13:09
User: mulad
Functions: echo read
0

The $[...] block in bash and zsh will let you do math.

echo $[6*7]

This is the same as using $((...)), which also works in ksh. Of course, this is a simple, dumb wrapper and doesn't allow floating-point.

perl -e 'use MIME::Base64; print encode_base64("encode me plz");'
2009-02-18 22:49:18
User: therek
Functions: perl
1

MIME::Base64 is a part of Perl5 distribution. You can also use decode_base64 for oposite result.

du -sk * | awk '{print $1} END {print "[+z1<y]sy\nlyx\np"}' | dc
ls *(m-1)
ls **/fred*~*junk*/*
while [ $(deborphan | wc -l) -gt 0 ]; do dpkg --purge $(deborphan); done
2009-02-18 22:31:22
User: mulad
Functions: wc
6

Upgraded Debian/Ubuntu/etc. systems may have a number of "orphaned" packages which are just taking up space, which can be found with the "deborphan" command. While you could just do "dpkg --purge $(deborphan)", the act of purging orphans will often create more orphans. This command will get them all in one shot.

ls -ld **/*(/^F)
for i in **/*.gif; convert $i $i:r.jpg
gst-launch v4l2src ! aasink
2009-02-18 22:17:53
User: rubenrua
-1

Use gstreamer to capture v4l2:///dev/video0 and show ascii art video in display.

cat .ssh/id_dsa.pub | ssh elsewhere "[ -d .ssh ] || mkdir .ssh ; cat >> .ssh/authorized_keys"
2009-02-18 22:13:04
User: jsiren
Functions: cat ssh
5

Enter your ssh public key in the remote end for future key-based authentication. Just type your password one last time. The next time you should be able to login with the public key. If you don't have a key, generate one with ssh-keygen.

Requires Bourne-compatible shell in the remote end.

while true; do /bin/true; done
2009-02-18 22:08:18
User: deepc0re
-3

Loads your CPU, run a instance for each CPU/CORE.

rsync -avz -e ssh username@hostname:/path/to/remote/dir/ /path/to/local/dir/
perl -lpe'1 while s/^([-+]?\d+)(\d{3})/$1.$2/'
cat /dev/urandom > /dev/dsp
2009-02-18 21:40:29
User: joem86
Functions: cat
4

This command will generate white noise through your speakers (assuming you have sound enabled). It's good for staying focused, privacy, coping with tinnitus, etc. I use it to test that the sound works.

(cd /Applications/Firefox.app/Contents/MacOS; ./firefox-bin -p default --no-remote)
watch -n 1 df
2009-02-18 21:34:06
User: joem86
Functions: watch
5

While copying a large file that may take up a good chunk of your hard drive, start the copy and run this command concurrently. It will print out the disk information every second. It's pretty handy when you have a large copy with nothing to monitor the progress.

for i in *; do mv "$i" "$(echo $i|tr A-Z a-z)"; done
2009-02-18 21:29:28
User: mulad
Functions: mv
5

This will convert filenames from uppercase to lowercase. I find this useful after downloading images from my digital camera. This works for English, but other languages may need something slightly more complex like this:

for i in *; do mv "$i" "$(echo $i|tr [:upper:] [:lower:])"; done

Also, the quote marks aren't necessary if your filenames don't contain spaces.