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.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

All commands from sorted by
Terminal - All commands - 12,363 results
find . -type f -mtime +7 -exec ls -l {} \;
2009-02-21 08:03:24
User: senses0
Functions: find ls

Find files that are older than x days in the working directory and list them. This will recurse all the sub-directories inside the working directory.

By changing the value for -mtime, you can adjust the time and by replacing the ls command with, say, rm, you can remove those files if you wish to.

N="filepath" ; P=/proc/$(lsof +L1 | grep "$N" | awk '{print $2}')/fd ; ls -l $P | sed -rn "/$N/s/.*([0-9]+) ->.*/\1/p" | xargs -I_ cat $P/_ > "$N"
2009-02-21 02:31:24
User: laburu
Functions: awk cat grep ls sed xargs

Note that the file at the given path will have the contents of the (still) deleted file, but it is a new file with a new node number; in other words, this restores the data, but it does not actually "undelete" the old file.

I posted a function declaration encapsulating this functionality to http://www.reddit.com/r/programming/comments/7yx6f/how_to_undelete_any_open_deleted_file_in_linux/c07sqwe (please excuse the crap formatting).

doloop() { DONT=/tmp/do-run-run-run; while true; do touch $DONT; (sleep 30; rm $DONT;) & $1 ; if [ -e $DONT ]; then echo restarting too fast; return ; fi ; done }
2009-02-21 02:11:18
User: evil_otto
Functions: echo return rm sleep touch

This runs a command continuously, restarting it if it exits. Sort of a poor man's daemontools. Useful for running servers from the command line instead of inittab.

"some line input" | sort | uniq -c | sort -nr
for i in `ps aux | grep ssh | grep -v grep | awk {'print $2'}` ; do kill $i; done
a() { alias $1=cd\ $PWD; }
2009-02-21 01:53:01
Functions: alias

An easy way to create aliases for moving between many directories

curl -s -u username:passwd http://twitter.com/statuses/friends_timeline.rss|grep title|sed -ne 's/<\/*title>//gp' |festival --tts
alias mine='ps xco pid,command,%cpu,%mem,state'
ssh -t [email protected] /usr/bin/screen -xRR
2009-02-20 23:39:54
User: olifante
Functions: ssh

Long before tabbed terminals existed, people have been using Gnu screen to open many shells in a single text terminal. Combined with ssh, it gives you the ability to have many open shells with a single remote connection using the above options. If you detach with "Ctrl-a d" or if the ssh session is accidentally terminated, all processes running in your remote shells remain undisturbed, ready for you to reconnect. Other useful screen commands are "Ctrl-a c" (open new shell) and "Ctrl-a a" (alternate between shells). Read this quick reference for more screen commands: http://aperiodic.net/screen/quick_reference

alias timestamp='date "+%Y%m%dT%H%M%S"'
2009-02-20 23:18:30
User: olifante
Functions: alias

I often need to add a timestamp to a file, but I never seem to remember the exact format string that has to be passed to the date command to get a compact datetime string like 20090220T231410 (i.e yyyymmddThhmmss, the ISO 8601 format popular outside the US)

Play "foo.mpg" in your terminal using ASCII characters
2009-02-20 22:12:14
User: chrisclymer

mplayer -vo caca will give you a similar result but in color

rpm -qa --queryformat 'Installed on %{INSTALLTIME:date}\t%{NAME}-%{VERSION}-%{RELEASE}: %{SUMMARY}\n'
HOST=;for((port=1;port<=65535;++port)); do echo -en "$port ";if echo -en "open $HOST $port\nlogout\quit" | telnet 2>/dev/null | grep 'Connected to' > /dev/null; then echo -en "\n\nport $port/tcp is open\n\n";fi;done | grep open
ps auxwww | grep outofcontrolprocess | awk '{print $9}' | xargs kill -9
[[ test_condition ]] && if_true_do_this || otherwise_do_that
2009-02-20 21:45:21
User: stallmer

instead of writing:

if [[ "$1" == "$2" ]]; then

echo "$1 is equal $2"


echo "$1 differs from $2"


do write:

[[ "$1" == "$2" ]] && echo "$1 is equal $2" || echo "$1 differs from $2"

ps aux | awk '/name/ {print $2}'
2009-02-20 21:35:52
User: evil_otto
Functions: awk ps

This finds a process id by name, but without the extra grep that you usually see. Remember, awk can grep too!

egrep 'string1|string2' file
2009-02-20 20:41:33
User: jcgam69
Functions: egrep

search file for string1 or string2

lsof -i :80
type "C:\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat"
reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ValidCommunities
type C:\WINNT\system32\inetsrv\MetaBase.xml | find "DEBUG"
type C:\WINNT\system32\inetsrv\MetaBase.xml | find "400" | find "CustomError"
while [ 1 ]; do curl -s -u username:password http://twitter.com/statuses/friends_timeline.rss|grep title|sed -ne 's/<\/*title>//gp' | head -n 6 |festival --tts; sleep 300;done
2009-02-20 20:20:21
User: tomwsmf
Functions: head sleep

Pump up the chatter, run this script on a regular basis to listen to your twitter timeline.

This is a rough first cut using several cli clips I have spotted around. There is no facility to not read those things already read to you. This could also easily be put in a loop for timed onslaught from the chatterverse, though I think it might violate several pointsof the Geneva Convention

UPDATE - added a loop, only reads the first 6 twits, and does this every 5 mins.

say -v Vicki "Hi, I'm a mac"
2009-02-20 20:17:00
User: chrisclymer

Very entertaining when run on someone elses machine remotely ;)

date "+The time is %H:%M" | say
2009-02-20 20:14:53
User: las3rjock
Functions: date

On other systems, replace 'say' with the name of another text-to-speech engine, e.g. espeak ( http://espeak.sourceforge.net ) or festival ( http://www.cstr.ed.ac.uk/projects/festival )