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

Top Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 12,034 results
prev=0;next=1;echo $prev;while(true);do echo $next;sum=$(($prev+$next));prev=$next;next=$sum;sleep 1;done
while [ -n "`pgrep wget`" ]; do sleep 2 ;done; [ -e "/tmp/nosleep"] || echo mem >/sys/power/state
2009-09-06 05:51:20
User: kamathln
Functions: echo sleep
1

[Note: This command needs to be run as root].

If you are downloading something large at night, you can start wget as a normal user and issue the above command as root. When the download is done, the computer will automatically go to sleep. If at any time you feel the computer should not go to sleep automatically(like if you find the download still continuing in the morning), just create an empty file called nosleep in /tmp directory.

curl -Is slashdot.org | sed -ne '/^X-[FBL]/s/^X-//p'
awk 'BEGIN {a=1;b=1;for(i=0;i<'${NUM}';i++){print a;c=a+b;a=b;b=c}}'
2009-09-06 03:05:55
User: arcege
Functions: awk
Tags: awk
0

Does not require input to function or complete. Number of iterations controlled by shell variable $NUM.

<ctrl-shift-t>
2009-09-05 18:01:32
User: tobiasboon
Tags: firefox
-10

This is really not cli but I think it's neat.

alias ':q'='exit'
2009-09-05 17:59:50
User: tobiasboon
Functions: alias
Tags: vim alias exit :q
9

Put this in your ~/.bashrc file (or the equivalent)

If you use vim a lot, this alias will be immediately obvious. Your brain will thank you.

<ctrl-f> in ex mode in vim
2009-09-05 14:43:15
User: Vereb
Functions: ex
Tags: vim
4

If you are in ex mode in vim i.e. you've pressed ':'. You can edit the current command by pressing <ctrl-f>

lspci -v | perl -ne '/VGA/../^$/ and /VGA|Kern/ and print'
grep -oE "ssid=\".*\"" /etc/wpa_supplicant.conf | cut -c6- | sed s/\"//g | zenity --list --title="Choose Access Point" --column="SSID"
2009-09-05 10:41:05
Functions: cut grep sed
1

If you still connect to your wireless access point manually and need to use wpa_supplicant, the above fu will grep all of the known SSID from your wpa_supplicant.conf file, present it in a Zenity list and return the SSID name you choose. I've wrapped this command in to a bash script that then up's the interface, associates and autenticates. Saves me from using NetworkManager ;)

dd if=/dev/cdrom of=whatever.iso
2009-09-05 09:19:41
User: 0disse0
Functions: dd
Tags: backup dd iso dvd
8

A dear friend of mine asked me how do I copy a DVD to your hard drive? If you want to make a copy of the ISO image that was burned to a CD or DVD, insert that medium into your CD/DVD drive and (assuming /dev/cdrom is associated with your computer?s CD drive) type the following command

sudo dd if=/dev/hda1 of=/dev/hdb2
2009-09-05 09:16:52
User: 0disse0
Functions: dd sudo
5

This command clone the first partition of the primary master IDE drive to the second partition

of the primary slave IDE drive (!!! back up all data before trying anything like this !!!)

od -vt x1 /tmp/spaghettifile
sudo mknod /dev/ttyS4 c 4 68
2009-09-05 09:12:44
User: 0disse0
Functions: c++ mknod sudo
Tags: serial mknod tty
0

When you need to add another tty device that can automatically start at boot time

yes "$(seq 1 255)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done
echo capitalize | { dd bs=1 count=1 conv=ucase 2> /dev/null; cat ;}
curl -d api_key="$api_key" -d user_app_key="$user_app_key -d body="$body" -d post_method="default" http://api.ping.fm/v1/user.post
2009-09-04 23:20:33
User: matthewbauer
2

Updates your Ping.fm status and websites supported by ping.fm (like twitter, facebook, and google talk).

echo "SECRET MESSAGE" | gpg -e --armor -s | sendmail [email protected]
2009-09-04 20:47:12
User: flip387
Functions: echo gpg sendmail
3

A very simple command to send a signed and encrypted message from the command line using GPG Keys

[ "$1" == "--help" ] && { sed -n -e '/^# Usage:/,/^$/ s/^# \?//p' < $0; exit; }
2009-09-04 20:36:06
User: syladmin
Functions: sed
9

With this one liner you can easily output a standard help message using the following convention:

Usage: is the start marker

Stop at the last #

for x in *.ogg; do ffmpeg -i "$x" "`basename "$x" .ogg`.mp3"; done
2009-09-04 20:23:09
User: Superhuman
Tags: ffmpeg ogg mp3 for
-1

Converts all ogg files to mp3 files in the current directory.

cat /etc/passwd | openssl aes-256-cbc -a -e -pass pass:password | netcat -l -p 8080
2009-09-04 20:04:24
User: flip387
Functions: cat
10

Using OpenSSL we can encrypt any input we wish and then use Netcat to create a socket which can be connected to from an externally source (even using a Web Browser)

vimdiff <(svn cat "$1") "$1"
2009-09-04 18:41:40
User: plasticboy
Functions: cat
Tags: svn vim diff color
2

This will diff your local version of the file with the latest version in svn. I put this in a shell function like so:

svd() { vimdiff <(svn cat "$1") "$1"; }
find . -name .svn -prune -o -print
2009-09-04 17:41:33
User: arcege
Functions: find
Tags: svn find
6

Put the positive clauses after the '-o' option.

svn log fileName | sed -ne "/^r\([0-9][0-9]*\).*/{;s//\1/;s/.*/svn cat fileName@& > fileName.r&/p;}" | sh -s
2009-09-04 17:23:45
User: arcege
Functions: sed sh
Tags: svn sed shell
2

Manages everything through one sed script instead of pipes of greps and awks. Quoting of shell variables is generally easier within a sed script.

badblocks -vfw /dev/fd0 10000 ; reboot
2009-09-04 16:57:51
User: SuperFly
Functions: badblocks
0

THIS COMMAND IS DESTRUCTIVE. That said, lets assume you want to render your boot drive unbootable and reboot your machine. Maybe you want it to boot off the network and kickstart from a boot server for a fresh OS install. Replace /dev/fd0 with the device name of your boot drive and this DESTRUCTIVE command will render your drive unbootable. Your BIOS boot priority should be set to boot from HD first, then LAN.

ssh -f -L3307:127.0.0.1:3306 -N -t -x user@host sleep 600 ; mk-table-sync --execute --verbose u=root,p=xxx,h=127.0.0.1,P=3307 u=root,p=xxx,h=localhost
2009-09-04 16:54:25
Functions: sleep ssh
6

I wanted to keep a backup of my company database server on my local homeserver. After I found maatkit to sync databases, everything except security seemed fine. SSH takes care of that part.