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,856 results
find . -name "*.[ch]" -print | xargs grep -i -H "search phrase"
2011-06-05 23:27:30
User: jblaine
Functions: find grep xargs
Tags: find grep

Original submitter's command spawns a "grep" process for every file found. Mine spawns one grep with a long list of all matching files to search in. Learn xargs, everyone! It's a very powerful and always available tool.

rm -rf `find . -type d -name .svn`
hex() { echo $1 16op | dc; }
git add -u
echo "<?php phpinfo(); ?>" >> /srv/www/htdocs/test.php
curl http://ipecho.net/plain
xcopy /e/h/y /z/i /k /f src dest
2009-02-13 16:25:09
User: piyo

I can remember "cp -av" on Unix like systems to copy files and directories. The same can be done on Windows without extra software, somewhat.

The switches mean:

/E Copies directories and subdirectories, including empty ones.

Same as /S /E. May be used to modify /T.

/H Copies hidden and system files also.

/Y Suppresses prompting to confirm you want to overwrite an

existing destination file.

/Z Copies networked files in restartable mode.

/I If destination does not exist and copying more than one file,

assumes that destination must be a directory.

/K Copies attributes. Normal Xcopy will reset read-only attributes.

/F Displays full source and destination file names while copying.

I don't type that all the time, I stick it into a file called "cpav.cmd" and run that.

echo xcopy /e/h/y /z/i /k /f %1 %2 > cpav.cmd cpav zsh zsh2


ls -1 | awk 'BEGIN{srand()} {x[NR] = $0} END{print "Selected", x[1 + int(rand() * NR)]}'
2011-03-13 20:05:06
User: saibbot
Functions: awk ls
Tags: awk random

I use this command to select a random movie from my movie collection..

while true ; do sleep 1 ; clear ; (netstat -tn | grep -P ':36089\s+\d') ; done
2011-09-28 11:39:43
User: hute37
Functions: clear grep netstat sleep true

shell loop to scan netstat output avoiding loolback aliases (local/remote swap for local connections)

tac ~/.bash_history | grep -w
2013-09-07 15:53:30
User: hamsolo474
Functions: grep tac

greps your bash history for whatever you type in at the end returning it in reverse chronological order (most recent invocations first), should work on all distros.

works well as an alias

yes '' | head -n100
sed 's/#.*//' /etc/fstab | column -t
FOR /F "tokens=3* delims=[]=" %A IN ('SET ARRAY[') DO ( echo %A )
2010-08-10 12:08:26
User: Marco
Functions: echo

This command loops over all indexes of the system variable array ARRAY[] and puts its content into %A.

Create this array before, e.g. by

set ARRAY[0]=test1


set ARRAY[1]=test2

For using inside of a batch file, write %%A instead of %A.

IFS=$'\n'; LIST=`ls -1`; let TOT=`echo $LIST | wc -w`-1 ; array=($LIST); echo "Selected ${array[ ($RANDOM % $TOT) ]}"
2011-03-13 21:30:44
User: ntropia
Functions: echo wc
Tags: bash random

The same thing using only Bash built-in's.

For readability I've kept the variables out, but it could me made extremely more compact (and totally unreadable!) by stuffing everything inside the single echo command.

alias grip="grep -i"
2009-07-21 11:12:15
User: inof
Functions: alias

This is *NOT* about the -i option in grep. I guess everybody already knows that option. This is about the basic rule of life that the simplest things are sometimes the best. ;-)

One day when I used "grep -i" for the umpteenth time, I decided to make this alias, and I've used it ever since, probably more often than plain grep. (In fact I also have aliases egrip and fgrip defined accordingly. I also have wrip="grep -wi" but I don't use this one that often.)

If you vote this down because it's too trivial and simplistic, that's no problem. I understand that. But still this is really one of my most favourite aliases.

echo Selected $(ls -1 | sort -R | head -n 1)
ls -l !* | /usr/bin/grep '^d'
for USER in `ls /var/spool/cron`; do echo "=== crontab for $USER ==="; echo $USER; done
find . -type d -print0 | xargs -0 du -s | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {} | sort -rn
cat file_with_tabs.txt | perl -pe 's/\t/ /g'
2010-07-11 13:01:22
User: nikc
Functions: cat perl
Tags: cat perl replace

Replaces tabs in output with spaces. Uses perl since sed seems to work differently across platforms.

awk 'BEGIN {srand()} {print int(rand()*1000000) "\t" $0}' FILE | sort -n | cut -f 2-
2009-04-19 20:04:58
User: udim
Functions: awk cut sort

Replace FILE with a filename (or - for stdin).

declare -i aa ; aa=3*8 ; echo $aa
ip addr|grep "inet "
2009-07-22 07:38:06
User: RickDeckardt
Functions: grep

Shows a single line per interface (device), with its IPv4 settings.

Shorter command, better readability in output.

slocate filename/dirname
2009-08-29 03:28:08
User: unixbhaskar
Functions: slocate

After you install slocate ,the first thing you have to do with it to initialise the database by issuing a command " slocate -u" . And then onwards just give the filename or dirname as a argument to the slocate command will reveal the files/dirs location in the system along with path.Moreover over it's an securely way of looking into the file system.

file -L <library> | grep -q '64-bit' && echo 'library is 64 bit' || echo 'library is 32 bit'
2010-03-07 06:31:35
User: infinull
Functions: echo file grep
Tags: bash

file displays a files type

the -L flag means follow sym-links (as libraries are often sym-linked to another this behavior is likely preferred)

more complex behavior (*two* grep commands!) could be used to determine if the file is or is not a shared library.