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,230 results
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.

pgrep -fl
emerge -e system && emerge -e system && emerge -e world && emerge -e world
2009-02-18 13:51:31
User: enlightend

This is a command you see mentioned alot by Gentoo monkeys.

They say to use it after every update of GCC, any library you might use and glibc.

They argue that compiling and recompiling everything like this will optimize the system alot more because you are recompiling the entire system (gcc, glibc etc) with nativly compiled versions of themselves. Same goes for all libraries etc.

I doubt the difference in working speed is really worth the hours and hours you end up having your computer compile the same stuff again and again though.

printf "%50s\n"|tr ' ' -
2010-01-07 08:49:46
User: rodolfoap
Functions: printf tr

Better -and faster- using bash printf.

watch -n 1 :
2009-03-25 23:00:28
User: penpen
Functions: watch
Tags: Linux unix

'watch' repeatedly (default every 2 seconds, -n 1 => every second) runs a command (here ':', a shorthand for 'true'), displays the output (here nothing) and the date and time of the last run.

I thought it to be obvious but it seemingly is not: to exit use Ctrl-C.

grep -c '^From ' mbox_file
for i in $(seq 1 20); do while read line; do echo "$i: $line"; done<$i.py; done
perl -m'AptPkg::Cache' -le '$c=AptPkg::Cache->new; for (keys %$c){ push @a, $_ if $c->{$_}->{'CurrentState'} eq 'Installed';} print for sort @a;'
2011-03-14 23:56:43
User: dbbolton
Functions: perl sort

A space-padded version:

perl -m'AptPkg::Cache' -e '$c=AptPkg::Cache->new; for (keys %$c){ push @a, $_ if $c->{$_}->{'CurrentState'} eq 'Installed';} print "$_ " for sort @a;'
YEST=`perl -w -e '@yest=localtime(time-86400);printf "%d%.2d%.2d",$yest[5]+1900,$yest[4]+1,$yest[3];'`
2009-05-19 08:54:06
User: sharfah
Tags: perl

Returns yesterday's date in the format yyyyMMdd

find . -type d -exec sh -c "normalize-audio -b \"{}\"/*.mp3" \;
2009-12-08 03:13:13
Functions: find sh

Execute this in the root of your music library and this recurses through the directories and normalizes each folder containing mp3s as a batch. This assumes those folders hold an album each. The command "normalize-audio" may go by "normalize" on some systems.

TOM=`perl -w -e '@tom=localtime(time+86400);printf "%d%.2d%.2d",$tom[5]+1900,$tom[4]+1,$tom[3];'`
2009-05-19 08:54:27
User: sharfah
Tags: perl

Returns tomorrow's date in the format yyyyMMdd

2010-09-11 18:51:41
User: mensa13

In case the line you want to join start with a char different than ", you may use \n.*"\n as regex.

echo $PATH|awk -F: ' { for (i=1; i <= NF; i++) print $i }'
IFS=`echo -en "\n\b"`; for i in $(curl http://feeds.digg.com/digg/container/technology/popular.rss | grep '<title>' | sed -e 's#<[^>]*>##g' | tail -n10); do echo $i; echo $i | sed 's/^/Did you hear about /g' | say; sleep 30; done
2010-06-07 22:16:19
User: echosedawk
Functions: echo grep sed sleep tail
Tags: bash sed curl osx

Instead of having someone else read you the Digg headlines, Have OSX do it. Requires Curl+Sed+Say. This could probably be easily modified to use espeak for Linux.

:bufdo %s/foo/bar/ge | up
dpkg --get-selections | awk '$2=="install" {print $1}' | sort
wget http://www.commandlinefu.com/commands/by/e7__7dal