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

Commands using sort from sorted by
Terminal - Commands using sort - 630 results
ps -eo pcpu,pid,args | sort -n
2009-02-16 14:23:03
Functions: ps sort
3

Useful to detect which process is causing system loads. It shows process PID so as we can take further actions.

du -ks * | sort -n
2009-02-16 14:18:52
Functions: du sort
-1

Very useful for finding the largest files and subdirectories at any given point. Any user can run it from current location just when need to know their largest files and subtdirectories from a certain point down as well.

netstat -anl | grep :80 | awk '{print $5}' | cut -d ":" -f 1 | uniq -c | sort -n | grep -c IPHERE
2009-02-16 08:54:08
User: nullrouter
Functions: awk cut grep netstat sort uniq
3

This will tell you who has the most Apache connections by IP (replace IPHERE with the actual IP you wish to check). Or if you wish, remove | grep -c IPHERE for the full list.

netstat -pant 2> /dev/null | grep SYN_ | awk '{print $5;}' | cut -d: -f1 | sort | uniq -c | sort -n | tail -20
2009-02-16 08:49:38
3

List top 20 IP from which TCP connection is in SYN_RECV state.

Useful on web servers to detect a syn flood attack.

Replace SYN_ with ESTA to find established connections

du -hs * | grep '^[0-9,]*[MG]' | sort -rn
netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | sed s/::ffff:// | cut -d: -f1 | sort | uniq -c | sort -n
find -printf '%u %g\n' | sort | uniq
2009-02-13 22:42:49
User: leper421
Functions: find sort
8

find -printf '%u\n' | sort | uniq #just users

find -printf '%g\n' | sort | uniq #just groups

history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 /file/of/ip/addresses
find / -xdev -size +1024 -exec ls -al {} \; | sort -r -k 5
ls -la | awk '{print $5, " " ,$9}' | sort -rn
last | awk '{ print $1 }' | sort | uniq -c | grep -v wtmp
sed -e 's/ *$//' ~/.bash_history | sort | uniq -cd | sort -nr | head
kill -HUP ` ps -aef | grep -i firefox | sort -k 2 -r | sed 1d | awk ' { print $2 } ' `
# cut -d ' ' -f1 /var/log/nginx/nginx-access.log | sort | uniq -c | sort -nr | head -10 | nl
perl -pe 's/.+;//' ~/.zsh_history | sort | uniq -c | sort -r|head -10
cd ~/.purple/logs/; egrep -ri "i can haz|pwn|l33t|w00|zomg" * | cut -d'/' -f 3 | sort | uniq | xargs -I {} echo "Note to self: ban user '{}'"
find $PWD -exec rpm --query -f {} \; | sort -u | grep -v "not owned"
2009-02-05 19:33:43
User: wwest4
Functions: find grep rpm sort
0

shows all RPMs with files in the current directory & its subdirectories.

netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c
echo "SHOW PROCESSLIST\G" | mysql -u root -p | grep "Info:" | awk -F":" '{count[$NF]++}END{for(i in count){printf("%d: %s\n", count[i], i)}}' | sort -n
sudo lsof | awk '{printf("%s %s %s\n", $1, $3, $NF)}' | grep -v "(" | sort -k 4 | gawk '$NF==prv{ct++;next} {printf("%d %s\n",ct,$0);ct=1;prv=$NF}' | uniq | sort -nr
for i in $(locate your_search_phrase); do dirname $i; done | sort | uniq
2009-02-05 14:03:20
User: realbrewer
Functions: dirname locate sort
1

Ever use 'locate' to find a common phrase in a filename or directory name? Often you'll get a huge list of matches, many of which are redundant, and typically the results are not sorted. This command will 'locate' your search phrase, then show you a sorted list of just the relevant directories, with no duplications. So, for example, maybe you have installed several versions of the java jre and you want to track down every directory where files matching "java" might exist. Well, a 'locate java' is likely to return a huge list with many repeated directories since many files in one directory could contain the phrase "java". This command will whittle down the results to a minimal list of unique directory names where your search phrase finds a match.

tar -tvjf backup.tar.bz2 | sort -nrk 3 | head
du -s * | sort -n | tail
alias counts=sort | uniq -c | sort -nr