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.

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 - 11,926 results
sort -R /usr/share/dict/british | grep -v -m4 ^\{1,10\}$ | tr [:upper:] [:lower:] | tr "\n" " " | tr -d "'s" | xargs -0 echo
2011-08-16 10:11:21
User: takac
Functions: grep sort tr xargs
Tags: tr xkcd
-1

Doesn't use shuf, its much faster with "shuf -n4" instead of sort -R

pcregrep --color -M -N CRLF -e "SQLEngine\.\w+\W*\([^\)]*\)" -r --include='\.java$'
tcpdump -s 1024 -l -A -n host 192.168.9.56
2013-02-02 22:29:52
User: wejn
Functions: host tcpdump
Tags: http tcpdump
-1

This is a better way to do the "src X or dst X" filter; plus you might not want to bother with DNS lookups (-n).

aspell -d en dump master | aspell -l en expand > words
xdg-open .
2010-10-05 04:20:31
User: schlaegel
-1

Opens the current working directory in the user's preferred application using freedesktop.org's xdg-open.

echo `cat /dev/urandom | base64 | tr -dc "[:alnum:]" | head -c64`
2010-12-06 21:04:57
User: Dereckson
Functions: echo head tr
-1

The same command, but with a base64 filter, more forgiving for special characters than tr.

sed 's/.$//' Win-file.txt
VBoxManage list systemproperties
2010-04-23 06:43:49
User: 0disse0
Tags: virtualbox
-1

How to show the system properties of a Sun VirtualBox server

wget --quiet -O - checkip.dyndns.org | sed -e 's/[^:]*: //' -e 's/<.*$//'
2010-08-01 13:36:08
User: berkes
Functions: sed wget
Tags: ip address
-1

Wgets "whatismyip" from checkip.dyndns.org and filters out the actual IP-adress. Usefull when you quickly need to find the outward facting IP-address of your current location.

exiv2 *JPG | grep Focal | awk '{print $5}' | sort -n | uniq -c
2011-07-05 11:25:29
User: ivanatora
Functions: awk grep sort uniq
-1

First column is number of photos, second column is the focal length.

pdfcrack <FILE>
find /var/www/ -type f -print0 | xargs -0 chmod 644
2013-03-28 11:10:30
User: FiloSottile
Functions: chmod find xargs
Tags: find xargs chmod
-1

xargs is a more elegant approach to executing a command on find results then -exec as -exec is meant as a filtering flag.

expanded_script=$(eval "echo \"$(cat ${sed_script_file})\"") && sed -e "${expanded_script}" your_input_file
2009-05-07 14:21:14
Functions: eval sed
-1

With this command you can use shell variables inside sed scripts.

This is useful if the script MUST remain in an external file, otherwise you can simply use an inline -e argument to sed.

STAT=`curl http://www.whatismyip.org/`; curl -u YourUserName:YourPassword -d status=$STAT http://twitter.com/statuses/update.xml
2009-10-26 23:02:30
User: m33600
-1

Easy way to find your computers IP in one place, ie, twitter

It suppress the need of dyndns clients and remembering the complex names they give you.

I put it inside KAlarm ( the cron GUI for KDE, ubuntu), to update my ip every 3 minutes.

I did not add the cron statements to keep the code clean.

VBoxManage showvminfo "cicciobox" --details
2010-04-23 06:45:29
User: 0disse0
Tags: virtualbox
-1

where "cicciobox" is the name of your virtual machine in a Sun VirtualBox server

zip -r homard homard -x homard/.git\*; cp ./homard.zip /path_to_dropbox_public_folder/homard.zip
2010-06-30 22:19:39
User: juliend2
Functions: cp
Tags: git zip dropbox
-1

If like me you do a lot of front-end coding and you have a lot of clients that asks you some little modifications, then you send the modifications back to them in a zip file while ignoring the .git folder and .gitignore file, then copy this zip into your dropbox and send it back to them. They find out a new bug so, rince and repeat? You get the picture. It can be quite tedious.

alias duh='dulist=$(du -sh */); for i in T G M K; do printf "$dulist"|egrep "^[0-9\.]+$i" | sort -rn; done'
2010-12-07 11:11:26
User: forcefsck
Functions: alias du egrep printf sort
Tags: disk usage
-1

Alias to produce a list of all subdir sizes in current dir, in reverse order and human readable units. du is executed only once. Remove the slash after the asterisk to include files.

echo -n "String to get MD5" | md5sum | sed "s/ -//"
diskutil list
find /dev/vg00 -type b -exec lvextend -m 1 {} /dev/disk/<disk> \;
2010-02-24 18:41:33
User: Glip
Functions: find
Tags: hp-ux lvm
-1

Mirror every lvol in vg00 in hp-ux 11.31

VBoxManage list ostypes
2010-04-23 06:50:42
User: 0disse0
-1

If you want to know what OS are supported on "guest" machines on the Sun VirtualBox server.

mplayer -vo fbdev $1 -fs -subcp ${2:-cp1251} -vf scale=${3:-1280:720}
2011-03-04 00:55:55
User: vkolev
-1

It's made for a script use, where you have 3 parameters:

1. parameter is the filename

2. (optional) the encoding for subtitles

3. (optional) the scaling of the video, since fullscreen doesn't mean that the video will be scaled.

tail -f ~/.bash_history
2011-09-15 19:35:09
User: totti
Functions: tail
Tags: watch
-1

Changes are displayed when they are written to the file

to exit

gnome-open .
VBoxManage createvm --name "vm-name" --ostype Ubuntu --register