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.


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:



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.




All commands from sorted by
Terminal - All commands - 11,491 results
C:\> shutdown /f /r /t 0
2014-04-02 22:35:00
User: mpb
Functions: shutdown

Today, I needed to reboot a Windoze machine on another continent which had no shutdown or restart options via "Start" in the remote desktop (the only options available were: "Logoff, Disconnect, or Lock").

Fortunately, I found how to shutdown and restart from the command line.

hgrep() { ... } longer then 255 characters, see below
2014-04-02 16:40:36
User: Xk2c



if [[ ${#} -eq 0 ]]


printf "usage:\nhgrep [--nonum | -N | -n | --all-nonum | -an | -na] STRING\n"

return 1


while [[ ${#} -gt 0 ]]


case ${1} in

--nonum | -N | -n | --all-nonum | -an | -na)

builtin history | sed 's/^[[:blank:]]\+[[:digit:]]\{1,5\}[[:blank:]]\{2\}//' | grep -iE "(${*:2})"




builtin history | grep -iE "(${*})"






'hgrep -n' helps in using full grep support, e.g. search for _beginning_ of specific commands,

see example output

rename 's/\.sh//' ./*
2014-04-02 16:33:25
User: abhikeny
Functions: rename

The 'rename' command with the first argument as "'s/\.//'" and the second argument as "" will remove the specified extension from the filenames.

function hg () { history | grep $* ; } # define a function combining history and grep to save typing :-)
2014-04-02 15:17:31
User: mpb
Functions: grep

By defining a function "hg" as shown here, it saves me typing "history | grep" every time I need to search my shell history because now I only have to type "hg".

A nifty time saver :-)

You can also add the "hg" function definition to your .bashrc so it is defined each time you login.

(prefix="10.59.21" && for i in `seq 254`; do (sleep 0.5 && ping -c1 -w1 $prefix.$i &> /dev/null && arp -n | awk ' /'$prefix'.'$i' / { print $1 " " $3 } ') & done; wait)
2014-04-02 11:20:57
User: smoky
Functions: arp awk ping sleep
Tags: ping

Waits for all pings to complete and returns ip with mac address

diff -qr /dirA /dirB
rsync -avz --dry-run /somewhere/source_directory /somewhereelse/target_directory
2014-04-01 20:55:59
User: tsener
Functions: rsync
Tags: diff rsync

--dry-run will only show you which files would be otherwise synced with rsync.

-z is for compressio

-v vervose

-a "as is" - permissions, ownership etc.

for output in $(find . ! -name movie.nfo -name "*.nfo") ; do rm $output ; done
2014-04-01 17:41:50
User: analbeard
Functions: find rm

Finds all nfo files without the filename movie.nfo and deletes them.

find directory -maxdepth 1 -iname "*" | awk 'NR >= 2'
2014-04-01 00:09:12
User: chilicuil
Functions: awk find

find . -maxdepth 1 -iname ".*" | awk 'NR >= 2'

Can be used to list only dotfiles without . nor ..

curl 'AudioStream' | ffmpeg -i - -acodec libvorbis file.ogg
2014-03-31 02:07:20
User: snipertyler

This encodes it in ogg format.

Does on-the-fly encoding of the incoming stream.

Great for radio streams as they're often flv format.

watch ls -lh /path/to/folder
2014-03-27 10:51:36
User: vonElfensenf
Functions: ls watch
Tags: pv

forgot to use a pv or rsync and want to know how much has been copied.

awk '$1=$1' FS=" " OFS=":" file
for i in *.svg; do convert "$i" "${i%.svg}.png" & done
2014-03-26 15:03:54
User: robinro

convert all *.svg to png _in parallel_

this speeds up the conversion for many files, but might also not be feasible for a large number of files

xxd -l 20 -c 20 -p /dev/urandom
2014-03-26 09:44:04
User: jt
Tags: password

Dumps 20 bytes from /dev/urandom and converts them to hex. -c and -p are needed to prevent splitting over lines.

echo 1395767373016 | gawk '{print strftime("%c", ( $0 + 500 ) / 1000 )}'
dpipe /usr/lib/openssh/sftp-server = ssh $REMOTE_HOST sshfs whatever:$LOCAL_PATH $REMOTE_PATH -o slave
2014-03-25 17:40:34
User: em
Functions: ssh

While `sshfs $REMOTE_HOST:$REMOTE_PATH $LOCAL_PATH` "pulls" a directory from the remote server to the local host, the above command does the reverse and "pushes" a directory from the local host to the remote server.

This makes use of the "slave" option of sshfs which instructs it to communicate over plain stdin/stdout and the `dpipe` tool from vde2 to connect the sftp-server stdout to the sshfs stdin and vice-versa.

find . -name '*.mp3' | sort | while read -r mp3; do echo -e "<h3>$mp3</h3>\n<audio controls src=\"$mp3\"></audio>"; done > index.html; python -m http.server
2014-03-24 15:01:49
User: hendry
Functions: echo find python read sort
Tags: audio browser

I tried a few curses based mp3 players for playing back choir practice songs for my wife.

Unfortunately none of the ones I tried were capable of scrubbing a track.

Firefox saves the day.

for i in *.svg; do convert "$i" "${i%.svg}.png"; done
2014-03-24 14:02:02
User: flatcap

Convert some SVG files into PNG using ImageMagick's convert command.

for i in *; do inkscape $i --export-png=`echo $i | sed -e 's/svg$/png/'`; done
ls -lF -darth `find . -mmin -3`
2014-03-22 16:52:20
User: UncleLouie
Functions: ls

Provides a recursive time ordered list of the current directory over the last 3 minutes.

Excluding zero byte files:

ls -lF -darth `find . -size +0 -mmin -3`

For the last day's files, change "-mmin -3" to "-mtime -1":

ls -lF -darth `find . -size +0 -mtime -1`
dmesg | grep -Po 'csum failed ino\S* \d+' | awk '{print $4}' | sort -u | xargs -n 1 find / -inum 2> /dev/null
2014-03-22 12:22:46
User: Sepero
Functions: awk dmesg find grep sort xargs
Tags: find inode btrfs

Btrfs reports the inode numbers of files with failed checksums. Use `find` to lookup the file names of those inodes. The files may need to be deleted and replaced with backups.

find ./ -type l -ls
find ./ -type l -print0 | xargs -0 ls -plah
2014-03-20 20:36:39
Functions: find ls xargs

shows you the symlinks in the current directory, recursively, but without following them

sed -n "/^.\{73,\}/p" < /path/to/file
2014-03-20 12:31:57
User: flatcap
Functions: sed

Filter out lines of input that contain 72, or fewer, characters.

"sed -n" : don't print lines by default

"/^.\{73,\}/" : find lines that start with 73 (or more) characters

"p" : print them

while read i; do [ ${#i} -gt 72 ] && echo "$i"; done < /path/to/file
2014-03-20 12:27:06
User: flatcap
Functions: echo read

Filter out lines of input that contain 72, or fewer, characters.

This uses bash only. ${#i} is the number of characters in variable i.