Hide

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.

Hide

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:

Hide

News

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.
Hide

Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 11,847 results
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
3

"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
6

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
0

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
3

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
0

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
1

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
5

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.

uptime
pstree -p
1

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
0

This will download all the phracks! Enjoy!

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

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'"

Or...

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
lynx http://shell-fu.org/
2009-08-20 11:47:35
User: penpen
-9

Today I learned that commandlinefu.com is not a alone in its conquest for further the knowledge about the command line. Allow me to introduce you to http://shell-fu.org/

watch() { t=$1; shift; while test :; do clear; date=$(date); echo -e "Every "$t"s: $@ \t\t\t\t $date"; $@; sleep $t; done }
( ( sleep 2h; your-command your-args ) & )
2009-08-19 17:39:11
User: sitaram
Functions: sleep
25

doesn't require "at", change the "2h" to whatever you want... (deafult unit for sleep is seconds)

watch() { while test :; do clear; date=$(date); echo -e "Every "$1"s: $2 \t\t\t\t $date"; $2; sleep $1; done }