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.

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





Commands using du from sorted by
Terminal - Commands using du - 208 results
du -sk * | sort -rn | head
2011-01-03 10:49:40
User: EBAH
Functions: du sort


* find . -type f -exec ls -s {} \; | sort -n -r | head -5

* find . -type f -exec ls -l {} \; | awk '{print $5 "\t" $9}' | sort -n -r | head -5

find . -type f -size +20000k -print0 | xargs -0 du -h | awk -F"\t" '{printf "%s : %s\n", $2, $1}'
2010-12-15 17:51:09
User: depesz
Functions: awk du find xargs

Output made so that it will match initial suggestion for this task. Personally, I think that output of du -h is more readable.

du -h |grep -P "^\S*G"
2010-12-13 15:26:31
User: girish_patel
Functions: du grep

This Command will list files & folders which are in GBs.

G can be replace by M to get files in MBs.

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

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.

du . -mak|sort -n|tail -10
2010-12-03 19:28:55
User: georgesdev
Functions: du sort tail

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

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

Directories listed in human-readable format

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

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

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

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.

du -sh ~/*
2010-11-05 10:20:16
Functions: du

Display the size (human reading) of all the directories in your home path (~).

du -b filename
ls -d1a /var/www/*/web | xargs du -hs
2010-10-18 17:16:23
User: DRoBeR
Functions: du ls xargs

Calculate foldersize for each website on an ISPConfig environment. It doesn't add the jail size. Just the "public_html".

du --max-depth=1|sort -n|cut -f2|tr '\n' '\0'|xargs -0 du -sh 2>/dev/null
du -a --max-depth=1 | sort -n
sudo du -sm * | sort -n
2010-09-24 17:56:41
User: wabi
Functions: du sort sudo

sudo is optional, but to find out about all files, it is nice, or else run as superuser, ie: su -c 'du -sm * | sort -n'

while true; do du -s <file_or_directory>; sleep <time_interval>; done
2010-08-24 19:55:13
User: potatoface
Functions: du sleep

very handy if you copy or download a/some file(s) and want to know how big it is at the moment

svn status | awk '{print $2}' | xargs du | sort -n | tail
while (( 1==1 )); do du -c . >> output.log; sleep 2; done; tail -f output.log
2010-07-12 17:23:45
User: aceiro
Functions: du sleep tail

this command shows the space used in postgres directory.

du -shc .[^.]* * | grep [MG]
2010-07-06 10:13:18
User: rubo77
Functions: du grep

shows only folders, that are MB or GB in total size

find . -type d -exec du -sk '{}' \; | awk '($1 < 2048) {print $2}'
2010-06-16 11:53:14
User: putnamhill
Functions: awk du find

Just shortened the awk a bit and removed sed. Edit: I'm assuming there are no spaces in the path. To support white space in pathname try:

awk '($1 < 2048) {sub(/^[0-9]+[ \t]+/,""); print $0}'
find . -type d -exec du -sk '{}' \; | awk '{ if ($1 <2000) print $0 }' | sed 's/^[0-9]*.//'
2010-06-16 09:37:56
User: mtron
Functions: awk du find sed

This command will search all subfolders of the current directory and list the names of the folders which contain less than 2 MB of data. I use it to clean up my mp3 archive and to delete the found folders pipe the output to a textfile & run:

while read -r line; do rm -Rv "$line"; done < textfile
du -hs /path/to/target
du -sm $dirname
du -h <Directory>
2010-06-04 03:14:37
User: Vasudev
Functions: du

Prints the size of Directory in human readable format like KB MB or GB. If you want to see size each files and directories inside the directory use -a option as shown in second output and if you want a total sum then add -c option :)