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

Commands using sort from sorted by
Terminal - Commands using sort - 670 results
netstat -ntu | awk ' $5 ~ /^[0-9]/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
2011-07-04 20:23:21
User: letterj
Functions: awk cut netstat sort uniq
Tags: netstat

netstat has two lines of headers:

Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address Foreign Address State

Added a filter in the awk command to remove them

netstat -ntu | awk ' $5 ~ /^[0-9]/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
compgen -c | sort -u > commands
2011-06-28 00:29:15
User: h3nr1x
Functions: sort
Tags: compgen

When you press TAB twice in your prompt, bash tells you something like

"Display all 4567 possibilities? (y or n)"

But when you press "y" you only get the list in the terminal output and, if you want to save it to a file, you have to copy it by hand from the vterm screen. With this utility you save the list to a file or pipe it to another command at will

You can use the file saved list to grep for a particular pattern, useful if you are searching for a command but you only remember a few letters

awk -F: 'BEGIN{a[NULL]=0;dupli[NULL]=0;}{if($3 in a){print a[$3];print ;}else a[$3]=$0;} ' /etc/passwd | sort -t: -k3 -n | sed -e 's/^/'$(hostname)':/g'
2011-06-22 05:14:30
Functions: awk sed sort

Prints all the lines in /etc/passwd belonging to users with a duplicated uid. It also adds the hostname to the beginning of the line.

It's been tested in AIX, Solaris and Linux.

netstat -nt | awk '{print $6}' | sort | uniq -c | sort -n -k 1 -r
netstat -n -f inet|awk '/\.389/{print $2}'|cut -f1-4 -d.|sort -u
tcpdump -nr capture.file | awk '{print }' | grep -oE '[0-9]{1,}.[0-9]{1,}.[0-9]{1,}.[0-9]{1,}' | sort | uniq -c | sort -n
2011-06-16 19:27:11
User: shahabv
Functions: awk grep sort tcpdump uniq
Tags: tcpdump

We can get useful statistics from tcpdump with this simple command.

Thanks "Babak Farrokhi" to teaching me this ;)

lsof | grep 'DEL.*lib' | sort -k1,1 -u
cat `ls -r /sys/class/net/*/address` | sort -u
lsof | grep 'DEL.*lib' | cut -f 1 -d ' ' | sort -u
2011-05-30 20:45:58
User: leenucks
Functions: cut grep sort

Useful after a complete system update (without a new kernel) when you want to know, which processes need to be restarted

sudo lsof | grep 'DEL.*lib' | cut -f 1 -d ' ' | sort -u
find . -maxdepth 1 -printf '%A@\t%p\n' | sort -r | cut -f 2,2 | head -1
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
for file in `find *| sort -n | sed 's% %?%g'`; do echo "${file//?/ }"; cp --parents "${file//?/ }" /destinity_folder/ ;done
sort -u < /sys/class/net/*/address
2011-05-18 17:50:44
User: marssi
Functions: sort
Tags: sort mac

List all MAC addresses on a Linux box. sort -u is useful when having virtual interfaces.

cat /proc/mounts | awk '{print $2}' | grep "^$MOUNTPOINT" | sort -r | xargs umount
2011-05-17 05:54:42
User: boni
Functions: awk cat grep sort xargs

Original: https://bugzilla.redhat.com/show_bug.cgi?id=194342

echo $(( $( date +%s ) - $( stat -c %Y * | sort -nr | head -n 1 ) ))
pacman -Qi $(pacman -Qq)|grep 'Name\|Size'| cut -d: -f2 | paste - - | column -t | sort -nk2
du -kh --max-depth=1 | sort -n |head
find . -printf '%d\n' | sort -n | tail -1
cut -f1 -d" " ~/.bash_history | sort | uniq -c | sort -nr | head -n 30
du --max-depth=1 -B M |sort -rn
2011-04-12 15:01:12
Functions: du sort
Tags: bash du sh

If you're only using -m or -k, you will need to remember they are either in Megabyte or kilobyte forms. So by using -B, it gives you the unit of the size measurement, which helps you from reading the result faster. You can try with -B K as well.

find /path/to/dir -type f |sed 's/^.*\.//' |sort -f |uniq -i
du -h --max-depth=1 | sort -hr
2011-04-07 18:01:18
User: splante
Functions: du sort
Tags: sort du

Credit goes to brun65i but he posted it as a comment instead as an alternative. I hadn't noticed the -h option on sort before and this seems like the cleanest alternative. Thanks Brun65i!

lynx --dump http://www.seeon.tv/channels| grep "/channels"|awk '{print $2}'|sort -u|while read links; do lynx --dump "$links"|awk '/view/ {print $2}'|sort -u; done
2011-04-01 05:58:20
User: Bonster
Functions: awk grep read sort

This shows a list of channels from seeon.tv website to watch shows and movies