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,610 results
for i in chmod chown; do sudo "$i" --reference=/home/user/copyfromfile /tmp/targetfile; done
2014-08-28 15:08:32
User: zlemini
Functions: chmod sudo

Copy both perms and owner group from one file to another.

ogr2ogr -f GeoJSON output.geojson input.shp
wget -qO- http://whatthecommit.com/index.txt | cowsay
2014-08-26 18:56:06
User: optyler
Functions: wget

No need to parse html page, website gives us a txt file :)

sprunge() { curl -F 'sprunge=<-' http://sprunge.us < "${1:-/dev/stdin}"; }
2014-08-26 17:47:31
User: malathion

echo "Hello world!" | sprunge # Redirect a stream to a pastebin

sprunge ~/.bashrc # Send a file to a pastebin

find . -type d -print0 | while read -d $'\0' dir; do cd "$dir"; echo " process $dir"; find . -maxdepth 1 -name "*.ogg.mp3" -exec rename 's/.ogg.mp3/.mp3/' {} \; ; cd -; done
2014-08-25 11:28:43
Functions: cd echo find read rename

This is probably overkill, but I have some issues when the directories have spaces in their names.


find . -type d -print0 | while read -d $'\0' dir; do xxx; done

loops over all the subdirectories in this place, ignoring the white spaces (to some extend).

cd "$dir"; echo " process $dir"; cd -;

goes to the directory and back. It also prints some info to check the progress.

find . -maxdepth 1 -name "*.ogg.mp3" -exec rename 's/.ogg.mp3/.mp3/' {} \;

renames the file within the current directory.

The whole should work with directories and file names that include white spaces.

curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"This is the title of the message","message":"This is the body of the message"},"id":1}' http://i3c.pla.lcl:8080/jsonrpc
2014-08-24 21:49:13
User: PLA

Send a text message to an Kodi (XBMC) device. Uses curl to post a JSON request to the Kodi JSON-RPC API.

tail -1f /var/opt/fds/logs/TraceEventLogFile.txt.0 | grep <msisdn> | tee <test-case-id>.trace | tr '|' '\n'
2014-08-21 19:29:07
User: neomefistox
Functions: grep tail tee tr

This command allows to follow up a trace on SDP (CS5.2), at the same time as the trace records are stored in the file with "raw" format.

Trace files in native format are useful to filter the records before to translation from '|' to '\n'.


grep -v OP_GET <raw-records>.trace | tr '|' '\n'
ffmpeg -acodec copy -vcodec copy -ss 00:05:00 -t 00:20:00 -i file.mp4 file_cropped.mp4
curl -L https://gist.github.com/westonruter/ea038141e46e017d280b/download | tar -xvz --strip-components=1
2014-08-19 22:19:44
User: westonruter
Functions: tar
Tags: gist


tr -dc '\x15-\x7e' < /dev/urandom| head -c 16 | paste
xclip -selection clipboard -o -t text/html | pandoc -f html -t markdown_github -
2014-08-18 20:47:46
User: keymon

I always wanted to be able to copy formatted HTML, like from emails, on trello cards or READMEs... but the formatting is always wrong... But from this two links:

* https://jeremywsherman.com/blog/2012/02/08/pasting-html-into-markdown/

* http://stackoverflow.com/questions/3261379/getting-html-source-or-rich-text-from-the-x-clipboard

For instance, to to copy an formatted email to a trello card, just:

1. Select the email body

2. run: xclip -selection clipboard -o -t text/html | pandoc -f html -t markdown_github - | xclip -i -t text/plain

3. Paste in your trello card

4. Profit!


YEAR=2015; echo Jul $(ncal 7 $YEAR | awk '/^Fr/{print $NF}')
2014-08-17 11:12:09
User: andreasS
Functions: awk echo
Tags: awk date

Calculate the date of Sysadmin day (last Friday of July) of any given year

YEAR=2015; date -d${YEAR}0801-$(date -d${YEAR}0801+2days +%u)days +%b\ %e
2014-08-17 11:06:25
User: andreasS
Functions: date
Tags: date

Calculate Sysadmin day of any given year using 2 `date`. Code based on http://stackoverflow.com/a/5656859/196133

YEAR=2015; ncal 7 $YEAR | sed -n 's/^Fr.* \([^ ]\+\) *$/Jul \1/p'
2014-08-17 11:04:02
User: andreasS
Functions: sed
Tags: sed date

Calculate the date of Sysadmin day (last Friday of July) of any given year

awp () { awk '{print $'$1'}'; }
echo 1 > /proc/sys/sunrpc/nfs_debug
2014-08-12 14:40:55
User: harpo
Functions: echo

echo 1 > /proc/sys/sunrpc/nfs_debug && tail -f /var/log/messages

to debug NFS issues.

eval echo $(echoprint-codegen "/path/to/file.mp3"| jq ' .[0].metadata | "mp3info -a \"" + .artist + "\" -t \"" + .title + "\" -l \"" + .release + "\" \"" + .filename + "\"" ' ) | bash
2014-08-08 21:14:53
User: glaudiston
Functions: echo eval

echoprint identify your song, then return artist, song name and album name(release) in a JSON. jq parse it and mp3info set the data in your mp3 file.

of course it depends on:




You need to set the environment variable


You can use it with find, but probably will bypass the 120 request/minute of developer account key. So, use a sleep to do it.

Something like:

find -name \*.mp3 | while read $f; do eval echo $(echoprint-codegen "$f" | jq ' .[0].metadata | "mp3info -a \"" + .artist + "\" -t \"" + .title + "\" -l \"" + .release + "\" \"" + .filename + "\"" ' ) | bash; sleep 1; done
[ `curl 'http://crl.godaddy.com/gds5-16.crl' 2>/dev/null | openssl crl -inform DER -noout -nextupdate | awk -F= '{print $2}' | xargs -I{} date -d {} +%s` -gt `date -d '8 hours' +%s` ] && echo "OK" || echo "Expires soon"
2014-08-07 17:18:38
User: hufman
Functions: awk date echo xargs
Tags: openssl

Downloads a CRL file, determines the expiration time, and checks when it will expire

sudo dpkg -P $(dpkg -l yourPkgName* | awk '$2 ~ /yourPkgName.*/ && $1 ~ /.i/ {print $2}')
2014-08-06 22:40:32
User: wejn
Functions: awk sudo
Tags: dpkg purge

Recently in Debian Wheezy the dpkg command refuses to work with wildcards, so this is the one-liner alternative. (alternative to #13614)

svn merge -r 854:853 l3toks.dtx
(echo -e '\x06\x00\x00\x00\x00\x00\x01\x01\x00'; sleep 1)|nc -c $host 25565
sudo dpkg -P $(sudo dpkg -l yourPkgName* | awk '$2 ~ /yourPkgName.*/' | awk '$1 ~ /.i/' | awk '{print $2}')
2014-08-02 18:14:02
User: woohoo
Functions: awk sudo
Tags: dpkg purge

Recently in Debian Wheezy the dpkg command refuses to work with wildcards, so this is the one-liner alternative.

Mac OSX: ping -oc 30 > /dev/null && say "Google name server is up" || say "This host is down"
2014-08-01 15:44:57
User: raulyca
Functions: ping
Tags: ping beep

Audio acknowledgement for host availability.

When running the command from a Linux systems, you can use "festival" or "espeak" instead of "say".

tar cvzf - dir | ssh my_server 'tar xzf -'
find /var/log -type f -iregex '.*[^\.][^0-9]+$' -not -iregex '.*gz$' 2> /dev/null | xargs tail -n0 -f | ccze -A
2014-07-29 17:11:17
User: rubo77
Functions: find tail xargs
Tags: unix ccze logging

This will show all changes in all log files under /var/log/ that are regular files and don't end with `gz` nor with a number