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.

Universal configuration monitoring and system of record for IT.
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 - 12,034 results
wget -r -nd -q -A "*.ext" http://www.example.org/
rsync -avz -e ssh username@hostname:/path/to/remote/dir/ /path/to/local/dir/
seq 10 |xargs -n1 echo Printing line
2009-10-15 11:05:35
User: Waldirio
Functions: echo seq xargs
Tags: echo xargs seq
0

Nice command to create a list, you can create too with for command, but this is so faster.

x11vnc -display :0 -scale 6/7 -rfbauth vncpass -forever
2009-11-12 21:32:45
0

This will start the x11vnc server, scale it at 6/7, will use the vncpass file to authenticate and wont shut down as soon as a client disconnects

{ echo -e "$body"; uuencode "$outfile" "$outfile"; } | mail -s "$subject" "$destaddr" ;
2009-12-10 18:08:59
User: glaudiston
Functions: echo mail uuencode
Tags: cat mail
0

on this way we can define the body too

:.,$!perl -pne 'for $i ("0001".."0004"){ s/XXXX/$i/ if($i == $.) }'
2010-02-11 03:56:26
User: bartonski
0

given lines of the form

123|XXXX|1000

...

123|XXXX|1011

each 'XXXX' will be replaced with a serial number between 0001 and 0004.

portnum() { egrep "[[:space:]]$*/" /etc/services; }
free -g
sudo find foldername -type f -exec chmod 644 {} ";"
apt-file --package-only search /lib/firmware
echo "main(i){for(i=0;;i++)putchar(((i*(i>>8|i>>9)&46&i >>8))^(i&i>>13|i>>6));}" | gcc -x c - && ./a.out | aplay
2013-01-09 21:48:23
User: r0nd0n
Functions: echo gcc
0

Something I pulled off 4chan, it plays a tune.

ssh user@remote "tar cfp - /path/to/log/* | gzip" > local.tar.gz
set +e +u; dd if=/dev/urandom of="/media/usb1/$$";sync;sync
2013-12-22 14:35:53
User: warkruid
Functions: dd set
0

I sometimes have use an usb stick to distribute files to several standalone "internet" pc's. I don't trust these machines period. The sticks I have do not have a write protection. So as a added security measure I fill the unused space on the (small) usb stick with a file with randomly generated bits. Any malware that tries to write to this stick will find no space on it.

Tested on slackware 14

Note: you may need root access to write to the device. This depends on your mount options.

ruby -run -e httpd . -p 8000
git log master...feature-a | grep -o -E '\b([A-Z]+)-[0-9]+\b' | sort | uniq
2014-07-07 18:51:01
User: westonruter
Functions: grep sort
0

To get the list of tickets in a comma-separated list, pipe the above into:

sort | uniq | perl -pe 's/\n/, /' | sed 's/, $//'
find . -name *.png | xargs optipng -nc -nb -o7 -full
srchpymod() { python -c "import $1; print filter(lambda x: x.find('$2') >= 0, dir($1))"; };
2009-02-16 02:47:13
User: jyro
Functions: python
0

srchpymod

for e.g.

srchpymod cairo Surface

['ImageSurface', 'PDFSurface', 'PSSurface', 'SVGSurface', 'Surface', 'SurfacePattern', 'XlibSurface']

cp ./* .[!.]* ..?* /path/to/dir
2009-03-16 13:27:36
User: ako
Functions: cp
0

./* is for copying files starting with -

.[!.]* is for copying hidden files and avoiding copying files from the parent directory.

..?* is for copying files starting with .. (avoids the directory ..)

/path/to/dir the path to the directory where the files should be copied

Can also be used as a script. Input argument is /path/to/dir

in tcsh, replace .[!.]* with .[^.]*

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
0

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
0

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
0

-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
0

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