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 - 637 results
netstat -alpn | grep :80 | awk '{print $4}' |awk -F: '{print $(NF-1)}' |sort | uniq -c | sort -n
last | grep -v "^$" | awk '{ print $1 }' | sort -nr | uniq -c
2009-02-18 16:38:59
User: hkyeakley
Functions: awk grep last sort uniq
15

This command takes the output of the 'last' command, removes empty lines, gets just the first field ($USERNAME), sort the $USERNAMES in reverse order and then gives a summary count of unique matches.

diff <(sort file1.txt) <(sort file2.txt)
2009-02-18 15:17:59
Functions: diff sort
4

Sees if two records differ in their entries, irrespective of order.

history | awk '{print $2}' | sort | uniq -c | sort -rn | head
egrep -o '\b[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\b' access.log | sort -u
find path/to/folder/ -type f -print0 | xargs -0 -n 1 md5sum | awk '{print $1}' | sort | md5sum | awk '{print $1}'
2009-02-16 19:39:37
User: mcover
Functions: awk find md5sum sort xargs
-2

For quick validation of folder's file-contents (structure not taken into account) - I use it mostly to check if two folders' contents are the same.

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n | tail
2009-02-16 15:48:27
User: TuxOtaku
Functions: awk cut netstat sort uniq
2

This command does a tally of concurrent active connections from single IPs and prints out those IPs that have the most active concurrent connections. VERY useful in determining the source of a DoS or DDoS attack.

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.