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.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





All commands from sorted by
Terminal - All commands - 12,272 results
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
echo -e $_{1..80}'\b+'
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'

ssh remotebox tail -f /var/log/remotelog
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.

function crtonl { perl -i -ape 's/\r\n?/\n/g;' $* ; }
2009-03-25 20:28:32
User: totoro
Functions: perl
Tags: files

Many Mac OS X programs, especially those in Microsoft:Office, create ASCII files with lines terminated by CRs (carriage returns). Most Unix programs expect lines separated by NLs (newlines). This little command makes it trivial to convert them.

/sbin/ifconfig eth0 | grep "inet addr" | sed -e 's/.*inet addr:\(.*\) B.*/\1/g'
ruby -e 'File.foreach("list") {|i| print `nslookup #{i}`}'
locate munin | xargs rm -r
htpdate -P proxy www.google.com www.yahoo.com www.commandlinefu.com
2009-02-13 17:31:11
User: piyo

HTP (HTTP Time Protocol) is an alternative way of getting "good enough" synchronized time. htpdate will give you near-second accuracy.

It works where NTP/SNTP does not because of firewalls and proxies. Of course, if NTP/SNTP can be used, use that instead.


htp is not in Ubuntu!

complete -W "$(while IFS=' ,' read host t; do echo $host; done < ~/.ssh/known_hosts)" ssh
2011-02-10 03:34:35
User: smax

Simple and fast variant, not using external programs. Another variation:

complete -W "$(while read line; do echo ${line%%[, ]*}; done < ~/.ssh/known_hosts)" ssh

HashKnownHosts must be off, of course.

pss() { ps -eo pid,args | sed '/'"$1"'/!d;/sed/d' ; }
2011-03-14 15:51:49
User: vando
Functions: ps sed

I know you can use pidof but with this you can know the specific PID with his command arguments (useful if you're running various proccess with same application)

command & echo $!
2011-06-08 18:16:38
User: Mahrud
Functions: command echo

Actually $! is an internal variable containing PID of the last job in background.

More info: http://tldp.org/LDP/abs/html/internalvariables.html#PIDVARREF

Using $! for job control:

possibly_hanging_job & { sleep ${TIMEOUT}; eval 'kill -9 $!' &> /dev/null; }
find . -user root | xargs sudo chown me:me
2012-04-24 18:29:13
Functions: chown find sudo xargs

be careful where you execute this from

do a 'sudo ls' beforehand to prime sudo to not ask for your password

lgrep() { /bin/ls -A --color=always ${2:-.} | /bin/grep $1 ; }
netstat -tunlp
2010-06-07 13:26:05
User: ender_x
Functions: netstat
Tags: netstat

Shows you all listening tcp/udp ports, and what program has them open(depending on rights)

seq -s^2+ 11 |rev| cut -d'+' -f2- | rev | bc
2011-02-10 08:41:14
User: rubenmoran
Functions: cut rev seq
Tags: seq sum math

I can't put the last ^2 with seq, so I reverse it to delete the last +N. So for doing sum(N^2) you have to do sum((N+1)^2). Must be a better way.