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
head -100000 /dev/urandom | strings|tr '[A-Z]' '[a-z]'|sort >temp.txt && wget -q http://www.mavi1.org/web_security/wordlists/webster-dictionary.txt -O-|tr '[A-Z]' '[a-z]'|sort >temp2.txt&&comm -12 temp.txt temp2.txt
grep -o -h -rE '".*"' * | ispell -l -p ~/mydict | sort -u
(netstat -atn | awk '{printf "%s\n%s\n", $4, $4}' | grep -oE '[0-9]*$'; seq 32768 61000) | sort -n | uniq -u | head -n 1
awk '{if ($1 ~ /Package/) p = $2; if ($1 ~ /Installed/) printf("%9d %s\n", $2, p)}' /var/lib/dpkg/status | sort -n | tail
lsof -iTCP -sTCP:ESTABLISHED | awk '{print $1}' | sort -u
alias duh='dulist=$(du -sh */); for i in T G M K; do printf "$dulist"|egrep "^[0-9\.]+$i" | sort -rn; done'
2010-12-07 11:11:26
User: forcefsck
Functions: alias du egrep printf sort
Tags: disk usage
-1

Alias to produce a list of all subdir sizes in current dir, in reverse order and human readable units. du is executed only once. Remove the slash after the asterisk to include files.

find /etc/rc3.d/ | sort -g
du . -mak|sort -n|tail -10
2010-12-03 19:28:55
User: georgesdev
Functions: du sort tail
1

du -m option to not go across mounts (you usually want to run that command to find what to destroy in that partition)

-a option to also list . files

-k to display in kilobytes

sort -n to sort in numerical order, biggest files last

tail -10 to only display biggest 10

functions(){ read -p "File name> "; sort -d $REPLY | grep "(){" | sed -e 's/(){//g' | less; }
2010-12-01 18:49:48
User: LinuxMan
Functions: grep read sed sort
0

This command finds all of the functions defined in any shell script you specify including .bashrc

du -hs */ | sort -hr | head
2010-11-28 15:08:01
User: eronisko
Functions: du sort
15

Directories listed in human-readable format

ps -eorss,args | sort -nr | pr -TW$COLUMNS | head
for file in $( vmrun list | grep 'vmx$' | sort ); do printf "% 40s %s M\n" $(echo "$( echo -n ${file}:\ ; grep memsize $file )" | sed -e 's/.*\///' -e 's/"//g' -e 's/memsize.=//'); done;
2010-11-19 06:14:11
Functions: echo file grep printf sed sort
Tags: vmware
-1

So your boss wants to know how much memory has been assigned to each virtual machine running on your server... here's how to nab that information from the command line while logged in to that server

ps -o euid,egid --ppid `netstat --inet --inet6 -pln|awk '/:80 / { split($7,tmp, "/"); print tmp[1]; }'`|sort |uniq|grep -v EUID
2010-11-18 21:22:29
User: chx
Functions: awk grep ps sort
-1

This command allows you to find the effective uid and gid of the Apache process regardless of process name (which can be apache2 or httpd depending on distro).

ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS
deadlib() { lsof | grep 'DEL.*lib' | cut -f 1 -d ' ' | sort -u; }
2010-11-17 12:53:30
User: Naib
Functions: cut grep sort
6

emerge,apt-get,yum... all update your system. This will at some point replace either a runtime dependency or a process (which is still running).

This oneliner will list what processes need to be restarted

history | awk '{print $2,$3}' | sed s/sudo// | awk '{print $1}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -n | tail | sort -nr
2010-11-17 12:15:04
User: b_t
Functions: awk sed sort tail uniq
0

Your version works fine except for someone who's interested in commands 'sudo' was prefixed to

i.e. in your command, use of sudo appears as number of times sudo was used.

Slight variation in my command peeks into what commands sudo was used for and counts the command

(ignores 'sudo')

history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -n | tail | sort -nr
ps ax -L -o pid,tid,psr,pcpu,args | sort -nr -k4| head -15 | cut -c 1-90
find /home/ -type f -exec du {} \; 2>/dev/null | sort -n | tail -n 10 | xargs -n 1 du -h 2>/dev/null
2010-11-10 07:24:17
User: mxc
Functions: du find sort tail xargs
Tags: disk usage
1

This combines the above two command into one. Note that you can leave off the last two commands and simply run the command as

"find /home/ -type f -exec du {} \; 2>/dev/null | sort -n | tail -n 10"

The last two commands above just convert the output into human readable format.

find / -type f -size +100M -exec du {} \; | sort -n | tail -10 | cut -f 2
find . -type f -size +500M -exec du {} \; | sort -n
2010-11-09 18:15:44
Functions: du find sort
Tags: size find
1

Greater than 500M and sorted by size.

find / -type f 2>/dev/null | xargs du 2>/dev/null | sort -n | tail -n 10 | cut -f 2 | xargs -n 1 du -h
2010-11-09 13:45:11
User: mxc
Functions: cut du find sort tail xargs
Tags: disk usage
1

Often you need to find the files that are taking up the most disk space in order to free up space asap. This script can be run on the enitre filesystem as root or on a home directory to find the largest files.

tr -cs A-Za-z '\n' | sort | uniq -ci
2010-10-20 04:12:58
Functions: sort tr uniq
Tags: sort uniq tr
0

Gives the same results as the command by putnamhill using nine less characters.

tr A-Z a-z | tr -cs a-z '\n' | sort | uniq -c
tr A-Z a-z | tr -d "[[:punct:]][[:digit:]]" | tr ' /_' '\n' | sort | uniq -c