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,925 results
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
54

Prints a graphical directory tree from your current directory

composite -compose Over rgba.png -tile xc:white -geometry `identify rgba.png | sed 's/[^ ]* [^ ]* \([^ ]*\) .*/\1/g'` rgb-white.png
2009-02-15 19:53:45
User: jimmac
Functions: sed
0

Use graphicsmagick or imagemagick to composite a RGBA image over a flat white background and discard the alpha channel.

convert -bordercolor Transparent -border 1x1 in.png out.png
2009-02-15 19:42:17
User: jimmac
-1

Requires either imagemagick or graphicsmagic utility.

find . -maxdepth 1 -iname '*jpg' -exec convert -quality 60 {} lowQ/{} \;
2009-02-15 19:34:38
User: abhinay
Functions: find
-1

* lowQ/ is the output directory

* pass quality level from 1 to 100

du -hs * | grep '^[0-9,]*[MG]' | sort -rn
mencoder "${file}" -of rawaudio -oac mp3lame -ovc copy -o audio/"${file/%avi/mp3}"
2009-02-15 14:57:54
User: fulat2k
5

This commands saves the output in the audio directory. The portion ${file/%avi/mp3} uses bash string replacement to replace the avi to mp3 within the ${file} variable.

useradd -s /sbin/nologin nicdev
eudcedit
2009-02-15 14:47:37
User: Williebee
-7

Create unique characters (up to 6400) used in the font library.

clgrep keyword
explorer /select,[file]
find "$DIR" -regex "$FILENAME" -type f -print0 | xargs -0 sed -i _`date "+%y%m%d%H%M%S"` -E "s/$TEXT1/$TEXT2/g"
netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | sed s/::ffff:// | cut -d: -f1 | sort | uniq -c | sort -n