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,490 results
perl -e '$x = []; push @$x, eval { $x = 1; return $x = 1; }'
2009-10-07 22:42:18
User: dstahlke
Functions: eval perl return

It is not easy to make perl give a segfault, but this does it. This is a known issue but apparently not easy to fix. This is completely useless except for showing people that perl is not bullet-proof.

sudo grub-install --root-directory=/media/ubuntu /dev/sda
2011-09-27 17:51:56
User: totti
Functions: sudo
Tags: grub boot fix

From live CD mount(open) the Ubuntu installed drive.

Copy the location (press Ctrl+l, Ctrl+c ) eg: /media/ubuntuuuu

Open terminal (Apllication->accessories->terminal)

Type this:

sudo grub-install --root-directory=/media/ubuntuuuu /dev/sda

(replace /media/ubuntuuuu with what u got (ie paste))

Will show success message. Now reboot

host `hostname`
2009-02-18 05:48:29
User: rommelsharma
Functions: host

This is a useful command that gives the hostname and the IP Address of your machine, on many OS. Tested on Linux and Solaris.

host command here is followed by `hostname`. Note the ` in the command is a back quote (or grave accent or back tic that usually shares the space with the ~ key). No other options are specified. See sample output.

wc -l `find . -name *.php`
echo "$(</etc/issue)"
2009-09-14 09:44:35
User: mobidyc
Functions: echo

another replacement for cat.

curl -s 'http://www.trynt.com/astrology-horoscope-api/v2/?m=2&d=23' | xmlstarlet sel -t -m '//horoscope' -v 'horoscope' | festival --tts
2009-02-23 16:52:06
User: mheadd

Uses curl, xmlstarlet and festival to speak your horoscope. Modify the m (month) and d (day) parameters to the astrology web service to hear your personal horoscope.

. filename [arguments]
2011-06-06 14:14:43
User: saibbot
Tags: shell

Read and execute commands from FILENAME in the current shell. The entries in $PATH are used to find the directory containing FILENAME. If any ARGUMENTS are supplied, they become the positional parameters when FILENAME is executed.

echo "[some repository]" | sudo tee -a /etc/apt/sources.list
2012-04-21 17:54:08
Functions: echo sudo tee

For instance, to add mongodb 10gen package

echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" | sudo tee -a /etc/apt/sources.list

cd /d d:\Windows
2009-02-13 16:06:48
User: piyo
Functions: cd

In the Windows cmd.exe window, you can change the directory using cd, but if you need to go to a directory on another drive, you need to type in the drive letter and colon first (e.g. d:). With the /d on cd, you don't need this intermediate step.

cd /?

Tested on Windows XP

hostname -i
2009-04-17 21:26:56
User: kFiddle
Functions: hostname
Tags: IP hostname

I've seen some versions of hostname that don't have the -i option, so this may not work everywhere. When available, it's a better alternative than using ifconfig and wasting eyeball muscle to search for the address, and it's definitely simpler than using awk/sed.

ifconfig | awk '/inet addr/ {print $2 }' | sed 's/.*://g'
2010-03-04 08:15:08
User: Guyverix
Functions: awk ifconfig sed

Easy way to grab the IP address of a machine for easy script use. If needed a "| grep -v" at the end will suppress localhost.

dpkg -L Your_Package
ssh -NL 12345:localhost:631 username@remote_server
sudo date mmddhhxxyyyy
find / | xargs ls -l | tr -s ' ' | cut -d ' ' -f 1,3,4,9
du -s `find . -maxdepth 1 \! -name '.'` | sort -n | tail
mount | awk '/:/ { print $3 } ' | xargs sudo umount
apt-cache show Your_package
perl -pi -e 's/([[:lower:]]+)/uc $1/gsex' file
2009-10-08 14:18:50
Functions: perl
Tags: perl

same, except it works on any OS with Perl installed. DOS, Windose, whatever

find . -type f -depth -3 -mtime -5
2009-03-25 19:54:06
User: totoro
Functions: find

Ever wanted to find the most recently modified files, but couldn't remember exactly where they were in a project directory with many subdirectories? The "find" command, using a combination of "-mtime -N" and "-depth -D" can be used to find those files. If your directory structure isn't very deep, just omit the "-depth -D", but if your directory structure is very deep, then you can limit the depth of the traversal using "-depth -D", where "D" is the maximum number of directory levels to descend.

ps ax| awk '/[h]ttpd/{print $1}'| xargs kill -9
find / -type f -size +20000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
find `pwd` -name '.*' -prune -o \( -name *.h -o -name *.cpp \) -print | cscope -bi-
2011-11-02 08:43:40
User: kev
Functions: find
Tags: find cscope

cd /

find `pwd` -name '.*' -prune -o \( -name *.h -o -name *.cpp \) -print | cscope -bi-

export CSCOPE_DB=/cscope.out

vim +'set cst'

ifconfig $DEVICE | perl -lne '/inet addr:([\d.]+)/ and print $1'
2009-07-21 13:48:19
User: jdob
Functions: ifconfig perl
Tags: IP

Found this useful for scripts where I needed to work with the machine's IP. If $DEVICE is not specified, this will return all IPs on the machine. If $DEVICE is set to a network adapter, it will return just that adapter's IP.

FOR /F "tokens=3* delims=[]=," %A IN ('SET ARRAY[') DO ( echo %A -- %B )
2010-08-10 12:12:27
User: Marco
Functions: echo

Loops over array of a system var, splits its values and puts the values into %A, %B, %C, %D, and so on.

Create array before, like

set ARRAY[0]=test1,100


set ARRAY[1]=test2,200

Be sure to replace %A, %B, etc. with %%A, %%B, etc. when using this from inside of batch files.