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,856 results
apt-show-versions <packagename>
2010-06-03 15:52:11
User: Vasudev
Functions: apt
Tags: Debian
-1

If there is update available for the package you can see upgrade is from which version to which version. Also you will get detail about which release the package belongs to (stable/testing/sid).

svn st | grep -e [MA] | egrep -ve '.project|.classpath|.properties|.sh|.number' | awk -F' ' '{ print $2}' | xargs svn ci -m "message"
diff --changed-group-format='differs from line %dF to line %dL|' --unchanged-line-format='' $FILE1 $FILE2 | sed 's/|/\n/'
2011-06-02 15:04:36
User: dullgiulio
Functions: diff sed
-1

Using sed to print newlines as doing it in one line with diff is non-trivial.

mkfifo ._b; nc -lk 4201 0<._b | /bin/bash &>._b;
2011-08-21 05:22:41
User: gt
Functions: mkfifo
Tags: bash nc mkfifo
-1

uses fifo and sets to a specific port. In this case 4201.

echo -n "password" | iconv -t utf-16le | openssl dgst -md4
tshark -qr [cap] -z conv,tcp | awk '{printf("%s:%s:%s\n",$1,$3,$10)}' | awk -F: '{printf("%s %s %s\n",$1,$3,substr($5,1,length($5)-10))}' | sort | uniq -c | sort -nr
find . -name "\.svn" -exec rm -rf {} ";"
function sepath { echo $PATH |tr ":" "\n" |sort -u |while read L ; do cd "$L" 2>/dev/null && find . \( ! -name . -prune \) \( -type f -o -type l \) 2>/dev/null |sed "s@^\./@@" |egrep -i "${*}" |sed "s@^@$L/@" ; done ; }
2009-09-11 15:03:22
User: mobidyc
Functions: cd echo egrep find read sed sort tr
Tags: bash ksh PATH
-1

search argument in PATH

accept grep expressions

without args, list all binaries found in PATH

alias ip4rev "echo \!* | sed 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\4.\3.\2.\1/'"
2009-02-09 17:00:03
Functions: alias
-1

For 'bash'

function ip4rev() { echo $@ | sed 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\4.\3.\2.\1/'; }
comm --nocheck-order -31
find -type f | xargs -I{} du -s "{}" | sort -rn | head | cut -f2 | xargs -I{} du -sh "{}"
2011-01-04 11:10:56
User: glaudiston
Functions: cut du find head sort xargs
-1

Show the top file size in human readable form

cvlc "v4l2:///dev/video0" --sout "#transcode{vcodec=mp2v,vb=800,scale=0.25,acodec=none}:file{mux=mpeg1,dst=/PATH/TO/OUTPUT/FILE}"
ssh user@remote "cat /remote/music/dir/*.mp3" | mpg123 -
2013-02-15 20:03:21
User: erix
Functions: mpg123 ssh
Tags: ssh Linux mpg123
-1

This is just a quick and dirty way to play remote audio files *locally* in your PC.

The best way is to mount the remote Music directory into the local FS, say by using sshfs:

sshfs user@remote:/remote/music/dir/ /mnt/other_pc/

ifconfig | awk '/HWaddr/ {printf "mac: %s addr: %s\n", $5, $1}'
ping -n 1 -w 10000 224.0.0.0
2009-08-26 02:25:07
User: DocGyver
Functions: ping
-1

In the vein of "can you do it better", here is my take on using "ping" to emulate sleep in a DOS/BAT script. If one can use ping at all then the multicast address will be valid but will not respond. By doing only one ping (-n 1) and setting a timeout in milliseconds (-w 10000) you have a fairly accurate timer. This example gives about a 10 second sleep.

ls -l directory | awk 'BEGIN { SUM=0 } { SUM+=$5 } END { print SUM/1024/1024"M" }'
convert -quality 40% original_image reduced_image
for L in `echo :$PATH | tr : '\n'`; do F=${L:-"."}/fileName; if [ -f ${F} -o -h ${F} ]; then echo ${F}; break; fi; done
2009-09-11 16:14:36
User: arcege
Functions: echo tr
-1

Searches in order of the directories of $PATH. Stops after finding the entry; looks for only that fileName. Works in Bourne, Korn, Bash and Z shells.

ffmpeg -i input.flv -vhook '/usr/lib/vhook/imlib2.so -c white -x 250 -y H+(-1.8*N+80) -t Hallo! -A max(0,255-exp(N/16))' -sameq -acodec copy output.flv
find -type f -exec du -sh {} + | sort -rh | head
find . -name '*.txt' -exec mv {} {}.sh \ ;
2011-06-02 23:47:19
Functions: find mv
-1

You can replace "." with your folder

MAC=$((date +'%Y%m%d%H%M%S%N'; cat /proc/interrupts) | md5sum | sed -r 's/(..)/\1:/g' | cut -d: -f 1-6)
2011-07-14 13:11:50
User: jazznjam
Functions: cat cut date md5sum sed
-1

I liked vaporub's suggestion, here a little simplification of the sed command.

convert example.png -resize 100x100 output.png
2010-08-08 16:40:21
User: dbbolton
-1

You can also specify width and height of the resized image (in pixels), as an alternative to using a percentage.

find . -name "*.png" | tee images.txt | grep book
2011-06-02 23:55:50
Functions: find grep tee
-1

You can find every file with png extension and redirect its output to file. Later you can find a string inside the file.

cp -dpRx /* /mnt/target/
2011-08-22 14:22:01
Functions: cp
-1

preserve all except context and xattr. useful when moving a running system to a new partition.