This question already has an answer here:

I'm looking for a script/program which will display the top x largest directories/files and then descend into those folders and display the x largest directories/files for a configurable depth.

231MB bin
 - 220MB ls
  - 190MB dir
  - 15MB def
  - 3MB lpr
 - 10MB asd
 - 1MB link

How can I do that?

marked as duplicate by ewwhite linux Dec 28 '14 at 21:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


You can see the 10 largest directories with:

du -cks *|sort -rn|head

This will recursively add up the sizes of everything in each directory - but you would have to manually execute it at each level to get a breakdown of what's in each

  • Should there be a - before cks? That's the case on Fedora. – oneodd1 Jun 12 '09 at 21:48
  • yes, there should be. It might be the markdown stealing it. – David Pashley Jun 12 '09 at 21:55
  • Yes, you are right - corrected it. – Brent Jun 12 '09 at 22:02
  • Thanks for the answer. I got this far myself, but got stuck on recursion :-) – Robert Munteanu Jun 12 '09 at 22:32

Chances are your system has one of these installed or available through your package manager:



  • ncdu - ncurses
  • gt5 - text browser (lynx, w3m, etc. - auto-selected) - It's actually a shell script!

They may not work exactly as you specified, but they should do most of what you need.


My variation on Brent's answer is:

# du -a | sort -rn | head

Which will give you the largest directories or files in the tree.

  • I would add the -h option to get better printed results for the size. – f.ederi.co Jun 12 '09 at 22:03
  • 2
    You can't add -h as then you'd end up with 2M being higher than 1G. – Adam Gibbins Jun 12 '09 at 22:22
  • Thanks for the answer. I got this far myself, but got stuck on recursion :-) – Robert Munteanu Jun 12 '09 at 22:33
  • 2
    GNU sort also supports the -h option. – alexanderpas Apr 22 '13 at 1:31

You could do some similar using find:

# find -maxdepth 2 -type d -exec du -sh {} \;

But this won't be sorted by size and will be incredible slow and inefficient. Better off writing a script that parses du -a.

  • there is a typo, this command should be : find . -maxdepth 2 -type d -exec du -sh {} \; – Guillaume Gendre Feb 7 '13 at 10:16

(Wanted to add this as a comment to Brent's answer but dont see a link to do that) I recently had a similar problem, and if you need to just check one partition in question, adding a -x to Brent's answer is pretty useful, especially if some directories have their own partition.

So it would be:

du -ckx / | sort -rn | head 

Something to remember about human-readable output is that a reverse numeric sort won't work as expected without fixing it up. A quicker option is to use the -k switch to output the directory size information in kilobytes.

I'd have a short look into the manpage of sort - on some systems you can use sort -h to sort human-readable output. I've used this on CentOS 6.2 with sort 8.4. Otherwise you can redirect the output of du -h to a file and sort that with something like:

for i in K M G; do egrep "^[0-9,\.]+${i}" somefile | sort -n; done

This gets you the sorted human-readable size of the top 10 largest files/folders in the entire directory tree:

du -ah | sort -hr | head


1019M   .
431M    ./prod
195M    ./prod/mainprogram
180M    ./utils
162M    ./prod/subprogram1
157M    ./.git
156M    ./py
155M    ./.git/objects
148M    ./.git/objects/pack
128M    ./prod/mainprogram/hdf

I don't know of a command-line tool that does this (other than what the other answers have suggested), but if you are able to run GUI programs on this machine, try KDirStat. It shows the disk usage of all files and directories under a particular root, sorted by size (by default).

Not the answer you're looking for? Browse other questions tagged or ask your own question.