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,611 results
sudo alsa force-reload
2009-02-16 03:30:13
User: oreo
Functions: sudo
-5

if you lose your sound, this will restart alsa and you will get your sound back

for (( i = 0; i < 100; i++ )); do echo "$i"; done
2009-02-16 03:19:26
User: themattrix
Functions: echo
1

Print 0 through 99, each on a separate line.

find . -type f -exec grep -l XXX {} \;|tee /tmp/fileschanged|xargs perl -pi.bak -e 's/XXX/YYY/g'
2009-02-16 02:55:23
User: drossman
Functions: find grep perl tee xargs
6

Find all files that contain string XXX in them, change the string from XXX to YYY, make a backup copy of the file and save a list of files changed in /tmp/fileschanged.

umount -l /media/foo
2009-02-16 02:51:49
User: nomad
Functions: umount
-2

Will unmount a mount that has already dropped but is locked by a process.

srchpymod() { python -c "import $1; print filter(lambda x: x.find('$2') >= 0, dir($1))"; };
2009-02-16 02:47:13
User: jyro
Functions: python
0

srchpymod

for e.g.

srchpymod cairo Surface

['ImageSurface', 'PDFSurface', 'PSSurface', 'SVGSurface', 'Surface', 'SurfacePattern', 'XlibSurface']

cd -
2009-02-16 02:37:50
User: chmouel
Functions: cd
1

cd - would return to the previous directory of your cd command. NB: previous dir is always stored in $OLDPWD variable.

killall nautilus
sudo dpkg --purge `dpkg -l | awk '/^r/{print $2}'`
2009-02-16 02:18:02
User: elleryq
Functions: awk sudo
2

After you install/remove lots of packages, there are many packages marked with 'rc'. This script help you to purge these packages, it will save some spaces from your disk.

echo 'example' | sed -e 's/^\(.\)/\U\1/'
zcat /usr/share/doc/vim-common/README.gz | vim -g +23 -
2009-02-16 01:25:37
User: int19h
Functions: vim zcat
1

This command is more for demonstrating piping to vim and jumping to a specific line than anything else.

Exit vim with :q!

+23 jumps to line 23

- make vim receive the data from the pipe

ls -F | grep '\''\*'\'' | sed '\''s/\*$//'\
xmms `python -c "print \"tone://\" + \";\".join([str(22*(2**x)) for x in range(9)])"`
for h in host1 host2 host3 host4 ; { scp file user@$h:/destination_path/ ; }
2009-02-16 01:02:35
Functions: file scp
7

Just a quick and simple one to demonstrate Bash For loop. Copies 'file' to multiple ssh hosts.

strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo
2009-02-16 00:39:28
User: jbcurtis
Functions: grep head strings tr
45

Find random strings within /dev/urandom. Using grep filter to just Alphanumeric characters, and then print the first 30 and remove all the line feeds.

for file in *.png; do convert "$file" "$(basename $file .png).gif"; done
2009-02-15 23:39:08
User: brettalton
Functions: file
3

(relies on 'imagemagick')

Convert all .png files to .gif. This can also go the other way if you reverse the file extensions in the command, e.g.:

for file in *.gif; do convert "$file" "$(basename $file .gif).png"; done

If the file is named 'example1.png' it will be named 'example1.gif' when it is complete.

for file in `ls *.pdf`; do convert -verbose -colorspace RGB -resize 800 -interlace none -density 300 -quality 80 $file `echo $file | sed 's/\.pdf$/\.jpg/'`; done
2009-02-15 23:27:43
User: brettalton
Functions: file sed
27

(relies on 'imagemagick')

This command will convert all .pdf files in a directory into a 800px (wide or height, whichever is smaller) image (with the aspect ratio kept) .jpg.

If the file is named 'example1.pdf' it will be named 'example1.jpg' when it is complete.

This is a VERY worthwhile command! People pay hundreds of dollars for this in the Windows world.

My .jpg files average between 150kB to 300kB, but your's may differ.

dd bs=1 count=32 if=/dev/random 2> /dev/null | md5 | grep -o '\w*'
./poweriso extract $USER/file.daa / -od $USER/file_extracted
2009-02-15 23:19:40
User: brettalton
-2

.daa is a non-standard disk image format that can not be read by any other program. This is how you can extract the files though.

PowerISO binary for Linux: http://www.poweriso.com/poweriso-1.3.tar.gz

"This is a free utility for linux which can extract, list, and convert image files (including ISO, BIN, DAA, and other formats). Type " poweriso -? " for detailed usage information. File Size: 278KB"

sudo aptitude -y install iasl && sudo cat /sys/firmware/acpi/tables/DSDT > dsdt.dat && iasl -d dsdt.dat
2009-02-15 23:13:50
User: brettalton
Functions: cat install sudo
-1

In July 2008, there was an uproar over Foxconn motherboards feeding Linux installs incorrect ACPI information (http://ubuntu-virginia.ubuntuforums.org/showthread.php?t=869249).

Foxconn has gladly corrected their mistake, but make sure it's not happening on your motherboard!

After running the command, just view the 'dsdt.dsl' in any editor you like.

mencoder -forceidx -ovc copy -oac copy -o output.avi video1.avi video2.avi
2009-02-15 23:05:32
User: brettalton
9

Use mencoder to concatenate (join) multiple video files together.

bdf | awk '(NF<5){f=$1; next} (NF>5){f=$1} {print f, $2, $3, $NF}'
defaults write com.apple.Dock showhidden -bool YES
2009-02-15 22:13:35
User: Vulpine
Functions: write
1

In Mac OS X, pressing Command+H will hide an application. While that application's windows vanish, there is no other visual feedback, meaning there is no immediate distinction between an application running with no windows open and a hidden application. This command turns hidden applications' icons transparent, providing a clear and obvious distinction.

Change YES to NO to restore the previous functionality.

wget http://search.twitter.com/trends.json -O - --quiet | ruby -rubygems -e 'require "json";require "yaml"; puts YAML.dump(JSON.parse($stdin.gets))'
apt-get moo
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
2009-02-15 20:43:21
Functions: grep ls sed
53

Prints a graphical directory tree from your current directory