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 - 12,018 results
xmlstarlet fo "http://www.google.com/ig/api?weather=$(curl -s api.hostip.info/get_html.php?ip=$(curl -s icanhazip.com)... SEE SAMPLE OUTPUT
2010-02-11 06:32:44
User: o0110o

This command will determine an individuals local weather, based on their I.P. address. I had to learn a lot about SED and a little about XMLStarlet in order to achieve this. This command is my original work and there is much room for improvement; I look forward to any constructive feedback.

function ttl { /usr/sbin/timetrans -count $(dig +noquestion +noadditional +noauthority $1 | grep "^$1" | awk '{print $2}') }
2010-11-22 17:46:03
User: cz8s
Functions: awk dig grep

This function uses timetrans from the dnssec-tools to calculate the remaining time until a dns entry reaches its time to live and is fetched from the authoritive nameserver again.

nohup cat /dev/ttyS0 | tee -a llamadas.db&
aptitude search ~i ~nfirmware
ffmpeg -i source.mpg -r 24 -f image2 still-%6d.png
2013-01-10 02:49:15
User: manuq

-i sets the source file

-r sets the output frame rate, set it to the same frame rate as the input to output each frame

-f sets the output format, trough it might be guessed by the extension

file -i `find . -name '*.jpg' -print` | grep "application/msword"
2013-03-10 16:53:23
User: genghisdani
Functions: file grep

Created to deal with an overzealous batch rename on our server that renamed all files to .jpg files.

ssh user@remotehost "find basedir -type d" | xargs -I {} -t mkdir -p {}
2013-07-17 07:14:32
User: neomefistox
Functions: mkdir ssh xargs

The directories are created in the local host with the same structure below of a remote base directory, including the 'basedir' in case that it does not exists.

You must replace user and remotehost (or IP address) with your proper values

ssh will ask for the password of the user in remotehost, unless you had included properly your hostname in the remote .ssh/known_hosts file.

mogrify -resize 852x480 *.png
2013-12-22 15:27:29
User: Tenzer

The mogrify command is also part of the ImageMagick suite, and is made to make changes to files in place.

pbpaste | say -v Alex -o /tmp/say.aiff && sox /tmp/say.aiff say.mp3
ls *.png | cut -d . -f 1 | xargs -L1 -i convert -strip -interlace Plane -quality 80 {}.png {}.jpg
xmms2 mlib search added \> $(echo $(date +%s) - 604800|bc)
find . -mtime +10
2010-04-12 14:50:08
User: rexington
Functions: find

This will find all files in the path "." which are older than 10*24hrs (10 days). This will find any type of file.

sudo tcpdump -i eth0 -n port 67 and 68
2010-08-18 19:36:06
User: wsv123456
Functions: sudo tcpdump

You don't need this command often and there are other ways to test output but if you want to be sure if your router and ethernet card are working this is one way.

nawk 'BEGIN {print srand()}'
2011-01-12 16:17:59
User: EBAH

For Solaris to obtain the same as:

date+%s like in linux

ps ax | grep -i ProcessName| kill -9 `awk '/FileName.Ext/ {print $1}'`
2011-03-24 02:49:49
User: bytesabit
Functions: grep kill ps

Outputs the PID of any given file run from a command line... Hope it helps!

for f in $(ls -A ./dir); do echo -n $f && diff original.txt ./dir/$f | wc -l ; done | perl -ne 'my $h={}; while (<>) { chomp; if (/^(\S+?)\s*(\d+?)$/){$h->{$1}=$2;} }; for my $k (sort { $h->{$a} $h->{$b} } keys %$h ){ print "$k\t$h->{$k}\n"}'
find . -type f -name "*.php" -exec wc -l {} +;
echo $(date -d @$((0x4f28b47e)))
netstat -an | grep 80 | wc -l
ffmpeg -i source.mpg -f s16le -acodec pcm_s16le audio.raw
2013-01-10 02:54:04
User: manuq

-i sets the source file

-f and -acodec both set the output to be raw audio, PCM signed 16-bit little endian

find /etc -type f -print0 | xargs -r0 grep --color ''
2013-04-30 15:03:20
User: jakezp
Functions: find grep xargs

find ip address in all files in /etc directory. can be used to find any string in any directory really

cut -d, -f1 /var/opt/example/dumpfile.130610_subscriber.csv | cut -c3-5 | sort | uniq -c | sed -e 's/^ *//;/^$/d' | awk -F" " '{print $2 "," $1}' > SubsxPrefix.csv
2013-07-17 07:58:56
User: neomefistox
Functions: awk cut sed sort uniq
Tags: Linux UNIX

dumpfile is a CSV file, which its 1st field is a phone number in format CC+10 digits

Empty lines are deleted, before the output in format "prefix,ocurrences"

convert multi_layer.tif -compress jpg multi_page.pdf
2013-09-26 14:44:01
User: algol

Creates a PDF file where each page will be a layer from de original TIFF file.

You can apply many other filters and transformations.

convert multi_layer.tif -page a4 -compress jpg multi_page.pdf

To set the page size

convert multi_layer.tif -crop 590x790+20+30 -compress jpg multi_page.pdf

To include only a portion of the image (discard first horizontal 20 pixels and first vertical 30 pixels, include the next 590 horizontal and 790 vertical pixels)

convert multi_layer.tif -delete 1,3,5-10 -compress jpg multi_page.pdf

Discard mentioned layers

git log --pretty=oneline --abbrev-commit
pbpate | sort | pbcopy