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 - 671 results
git ls-files | xargs -n1 -d'\n' -i git-blame {} | perl -n -e '/\s\((.*?)\s[0-9]{4}/ && print "$1\n"' | sort -f | uniq -c -w3 | sort -r
2009-10-25 01:44:03
User: askedrelic
Functions: perl sort uniq xargs
Tags: statistics git

Figures out total line contribution per author for an entire GIT repo. Includes binary files, which kind of mess up the true count.

If crashes or takes too long, mess with the ls-file option at the start:

git ls-files -x "*pdf" -x "*psd" -x "*tif" to remove really random binary files

git ls-files "*.py" "*.html" "*.css" to only include specific file types

Based off my original SVN version: http://www.commandlinefu.com/commands/view/2787/prints-total-line-count-contribution-per-user-for-an-svn-repository

shuf -i 1-49 | head -n6 | sort -n| xargs
2009-10-22 12:54:08
User: ioggstream
Functions: head sort

note the xargs at the end

echo $(shuf -i 1-49 | head -n6 | sort -n)
sed -ne '/^Package: \(.*\)/{s//\1/;h;};/^Installed-Size: \(.*\)/{s//\1/;G;s/\n/ /;p;}' /var/lib/dpkg/status | sort -rn
2009-10-19 19:01:17
User: arcege
Functions: sed sort

Use the hold space to preserve lines until data is needed.

perl -ne '$pkg=$1 if m/^Package: (.*)/; print "$1\t$pkg\n" if m/^Installed-Size: (.*)/;' < /var/lib/dpkg/status | sort -rn | less
2009-10-19 12:55:59
User: hfs
Functions: perl sort

List packages and their disk usage in decreasing order. This uses the "Installed-Size" from the package metadata. It may differ from the actual used space, because e.g. data files (think of databases) or log files may take additional space.

find . -type f -printf "%h\n" | cut -d/ -f-2 | sort | uniq -c | sort -rn
2009-10-09 23:49:53
User: ivancho
Functions: cut find sort uniq
Tags: file count

counts the total (recursive) number of files in the immediate (depth 1) subdirectories as well as the current one and displays them sorted.

Fixed, as per ashawley's comment

awk '{print length, $0;}' | sort -nr
find ~/Music -daystart -mtime -60 -name *mp3 -printf "%T@\t%p\n" | sort -f -r | head -n 30 | cut -f 2
find -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate
2009-09-21 00:24:14
User: syssyphus
Functions: find md5sum sort uniq xargs

This dup finder saves time by comparing size first, then md5sum, it doesn't delete anything, just lists them.

netstat -lantp | grep -i stab | awk -F/ '{print $2}' | sort | uniq
2009-09-19 14:54:31
User: ProMole
Functions: awk grep netstat sort

Show apps that use internet connection at the moment.

Can be used to discover what programms create internet traffic. Skip the part after awk to get more details, though it will not work showing only unique processes.

This version will work with other languages such as Spanish and Portuguese, if the word for "ESTABLISHED" still contain the fragment "STAB"(e.g. "ESTABELECIDO")

netstat -lantp | grep -i establ | awk -F/ '{print $2}' | sort | uniq
echo "Decode this"| tr [a-zA-Z] $(echo {a..z} {A..Z}|grep -o .|sort -R|tr -d "\n ")
find . -maxdepth 1 ! -name '.' -execdir du -0 -s {} + | sort -znr | gawk 'BEGIN{ORS=RS="\0";} {sub($1 "\t", ""); print $0;}' | xargs -0 du -hs
2009-09-11 16:07:39
User: ashawley
Functions: du find gawk sort xargs

A little bit smaller, faster and should handle files with special characters in the name.

diff <(ssh server01 'cd config; find . -type f -exec md5sum {} \;| sort -k 2') <(ssh server02 'cd config;find . -type f -exec md5sum {} \;| sort -k 2')
2009-09-11 15:24:59
User: arcege
Functions: diff find md5sum sort ssh

This can be much faster than downloading one or both trees to a common servers and comparing the files there. After, only those files could be copied down for deeper comparison if needed.

function sepath { echo $PATH |tr ":" "\n" |sort -u |while read L ; do cd "$L" 2>/dev/null && find . \( ! -name . -prune \) \( -type f -o -type l \) 2>/dev/null |sed "s@^\./@@" |egrep -i "${*}" |sed "s@^@$L/@" ; done ; }
2009-09-11 15:03:22
User: mobidyc
Functions: cd echo egrep find read sed sort tr
Tags: bash ksh PATH

search argument in PATH

accept grep expressions

without args, list all binaries found in PATH

pkg search SEARCH_TERM | awk '{print $NF}' | sed -e 's;.*/\(.*\)\@.*;\1;' | sort -u
find . -name '*.html' -exec 'sed' 's/.*class="\([^"]*\?\)".*/\1/ip;d' '{}' ';' |sort -su
2009-09-06 18:43:18
User: kamathln
Functions: find sort

Lists out all classes used in all *.html files in the currect directory. usefull for checking if you have left out any style definitions, or accidentally given a different name than you intended. ( I have an ugly habit of accidentally substituting camelCase instead of using under_scores: i would name soemthing counterBox instead of counter_box)

WARNING: assumes you give classnames in between double quotes, and that you apply only one class per element.

du -a --max-depth=1 | sort -n | cut -d/ -f2 | sed '$d' | while read i; do if [ -f $i ]; then du -h "$i"; else echo "$(du -h --max-depth=0 "$i")/"; fi; done
2009-09-03 20:43:43
User: nickwe
Functions: cut du echo read sed sort

Based on the MrMerry one, just add some visuals to differentiate files and directories

find . -maxdepth 1 -type d|xargs du -a --max-depth=0|sort -rn|cut -d/ -f2|sed '1d'|while read i;do echo "$(du -h --max-depth=0 "$i")/";done;find . -maxdepth 1 -type f|xargs du -a|sort -rn|cut -d/ -f2|sed '$d'|while read i;do du -h "$i";done
2009-09-03 20:33:21
User: nickwe
Functions: cut du echo find read sed sort xargs

Based on the MrMerry one, just add some visuals and sort directory and files

O=$IFS;IFS=$'\n'; D=$(for f in *;do [[ -d $f ]] && du -sh "$f";done | sort -gr);F=$(for f in *;do [[ -f $f ]] && du -sh "$f";done | sort -gr);IFS=$O;echo "$D";echo "$F"
2009-09-03 11:39:50
User: Viperlin
Functions: du sort

biggest->small directories, then biggest->smallest files

echo sortmeplease | grep -o . | sort | tr -d '\n'; echo
2009-09-03 00:52:49
User: MrMerry
Functions: echo grep sort tr

Sorts a character string, using common shell commands.

awk '{print $1}' /var/log/httpd/access_log | sort | uniq -c | sort -rnk1 | head -n 10
du -s `find . -maxdepth 1 \! -name '.'` | sort -n | tail
find /dir | awk '{print length, $0}' | sort -nr | sed 's/^[[:digit:]]* //' | while read dirfile; do outfile="$(echo "$(basename "$dirfile")" | unaccent UTF-8)"; mv "$dirfile" "$(dirname "$dirfile")/$outfile"; done
2009-08-24 21:24:18
User: Patola
Functions: awk basename find mv read sed sort

This command changes all filename and directories within a directory tree to unaccented ones. I had to do this to 'sanitize' some samba-exported trees. The reason it works might seem a little difficult to see at first - it first reverses-sort by pathname length, then it renames only the basename of the path. This way it'll always go in the right order to rename everything.

Some notes:

1. You'll have to have the 'unaccent' command. On Ubuntu, just aptitude install unaccent.

2. In this case, the encoding of the tree was UTF-8 - but you might be using another one, just adjust the command to your encoding.

3. The program might spit a few harmless errors saying the files are the same - not to fear.

find / -type f -exec wc -c {} \; | sort -nr | head -100