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,274 results
sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).in-addr.arpa domain name pointer\(.*\)\./\4.\3.\2.\1\5/' \ lookups.txt
2009-08-22 09:37:20
User: hemanth
Functions: sed
Tags: sed

Reverse DNS lookups, from a file with list of IP's, here the file is called lookups.txt

for i in `seq 1 255`; do ping -c 1 10.10.10.$i | tr \\n ' ' | awk '/1 received/ {print $2}'; done
2009-08-22 09:34:27
User: hemanth
Functions: awk ping tr
Tags: ping

Ping sweep without NMAP

for i in `cat names.txt`; do host -r $i [nameserver]; done
2009-08-22 09:26:31
User: hemanth
Functions: host
Tags: host

DNS cache snooping

chage -l <user>
for u in `cut -f1 -d: /etc/passwd`; do echo -n $u:; groups $u; done | sort
2009-08-22 09:06:02
User: hemanth
Functions: echo groups
Tags: sort cut for groups

"cut" the user names from /etc/passwd and then running a loop over them.

find . -type d -empty -delete
2009-08-22 09:03:14
User: hemanth
Functions: find
Tags: find rmdir

You can also use, $ find . -depth -type d -exec rmdir {} \; 2>/dev/null

echo $(( $RANDOM % 10 + 1 ))
echo init 0 | at now + 2 hours
export PS1='\D{%a %D %T}> '
lsof -Pni4 | grep LISTEN
for i in `grep "unable to stat" /var/log/syslog | cut -d "/" -f 3 | sort | uniq`; do find /var/qmail/queue -name $i -type f -exec rm -v {} \; ; done
mailq | grep DrWEB | awk {'print $1'} | sed s/*//g | postsuper -d -
id=<XXXX>; find /var/spool/postfix/ -name $id -exec less {} \;
find /var/www/ -type f -name ".htaccess" -exec perl -pi -e 's/AddHandler[\s]*php(4|5)-cgi/AddHandler x-httpd-php\1/' {} \;
2009-08-21 21:55:22
User: foob4r
Functions: find perl

Alter "AddHandler php5-cgi .php" and "AddHandler php4-cgi .php" entries to new "AddHandler x-httpd-php5 .php" respective php4 entries in all .htaccess files under /var/www

echo "scale=4; 3 / 5" | bc
2009-08-21 21:51:46
User: foob4r
Functions: echo

allows you to use floating point operations in shell scripts

cat filename | tr '\n' '\0' | du -hsc ?files0-from=-
2009-08-21 18:36:49
User: Diluted
Functions: cat du tr

du only accepts lines ending with a NUL, which can be a pain to create. This solves that issue.

yes | tr 'y' 'n'
find dir/ -type f | xargs tail -fqn0
2009-08-21 18:05:12
User: chickenzilla
Functions: find tail xargs

The `-q' arg forces tail to not output the name of the current file

curl http://www.phrack.org/archives/tgz/phrack[1-67].tar.gz -o phrack#1.tar.gz
cc -march=native -E -v - </dev/null 2>&1 | grep cc1
2009-08-21 09:47:37
User: manny79
Functions: c++ cc grep

You can tell GCC to automatically select optimization commands and produce optimized code for the local machine (the one compiling the code), but you can't normally see what switches have been selected and used unless you append a "-v" and pause compilation.

pstree -p

Shows a less detailed output, made only of the process tree and their pids.

for ((i=1; i<67; i++)) do wget http://www.phrack.org/archives/tgz/phrack${i}.tar.gz -q; done
2009-08-20 23:27:01
User: Abiden
Functions: wget

This will download all the phracks! Enjoy!

watch -n .5 "iwlist wlan0 scan"
2009-08-20 23:05:04
User: Abiden
Functions: watch

If you're like some individuals who rely on ndiswrapper and cannot use kismet, this command may be of service.

watch -n .5 "iwlist wlan0 scan | egrep 'ESSID|Encryption'"


watch -n .5 "iwlist wlan0 scan | egrep 'ESSID|Encryption' | egrep 'linksys'"

:-) Hopefully you'll find some dd-wrt compatible routers.

sync; echo 3 > /proc/sys/vm/drop_caches