Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say I want to get the size of each folder of a linux file system. When I use ls -la I don't really get the summarized size of the folders.

If I use df I get the size of each mounted file system but that also doesn't help me. And with du I get the size of each subfolder and the summary of the whole file system.

But I want to have only the summarized size of each folder within the ROOT folder of the file system. Is there any command to achiev that?

share|improve this question

migrated from Jul 12 '10 at 18:25

This question came from our site for professional and enthusiast programmers.

up vote 256 down vote accepted
du -sh /*

-s to give only the total for each command line argument, -h for human-readable suffixes (optional). /* simply expands to all directories (and files) in /.

share|improve this answer
If you have dot-directories in the root directory, you can use shopt -s dotglob to include them in the count. – Philipp Jul 11 '10 at 21:55
It's very usefull, because it's simple and you can place what path you want instead of /*, e.g. ./ for current directory or ./* for each item in current directory. – psur Aug 9 '12 at 6:22
@psur or you can use ./*/ to get only subfolders and not all items – relascope Jan 28 at 23:48

I often need to find the biggest directories, so to get a sorted list containing the 20 biggest dirs I do this:

du -m /some/path | sort -nr | head -n 20

In this case the sizes will be reported in megabytes.

share|improve this answer
Here's a way to get it more readable du -sh /some/path | sort -hr | head -n 20 – Xedecimal Jul 8 '13 at 15:49
@Xedecima the problem with using h is the sort doesn't know how to handle different sizes. For example 268K is sorted higher than 255M, and both are sorted higher than 2.7G – chrisan Dec 27 '13 at 18:33
The -h (human readable) argument on the 'sort' command should properly read these values. Just like du's -h flag exports them. Depending on what you're running I'm guessing. – Xedecimal Apr 14 '14 at 18:02

The existing answers are very helpful, maybe some beginner (like me) will find this helpful as well.

  1. Very basic loop, but for me this was a good start for some other size related operations:

    for each in $(ls) ; do du -hs "$each" ; done
  2. Very similar to the first answer and nearly the same result as 1.), but it took me some time to understand the difference of * to ./* if in a subdirectory:

    du -sh ./*
share|improve this answer

I like to use Ncdu for that, you can use the cursor to navigate and drill down through the directory structure it works really well.

share|improve this answer

The following du invocation should work on BSD systems:

du -d 1 /
share|improve this answer
My du (Ubuntu 10.4) doesn't have a -d option. What system are you on? – Thomas Jul 11 '10 at 17:30
On my openSUSE it doesn't have a -d option either :( – 2ndkauboy Jul 11 '10 at 17:33
OK, then it's a BSD option only (I'm on OS X). – Philipp Jul 11 '10 at 17:37
Right portable option combination on BSD/*NIX is du -sk /*. I hate the -k stuff soooo much. Linux' -h totally rocks. – Dummy00001 Jul 11 '10 at 19:46
in other systems, its --max-depth – Vishnu Kumar Sep 1 '15 at 12:49

This isn't easy. The du command either shows files and folders (default) or just the sizes of all items which you specify on the command line (option -s).

To get the largest items (files and folders), sorted, with human readable sizes on Linux:

du -h | sort -h

This will bury you in a ton of small files. You can get rid of them with --threshold (1 MB in my example):

du --threshold=1M -h | sort -h

The advantage of this command is that it includes hidden dot folders (folders which start with .).

If you really just want the folders, you need to use find but this can be very, very slow since du will have to scan many folders several times:

find . -type d -print0 | sort -z | xargs --null -I '{}' du -sh '{}' | sort -h
share|improve this answer
--threshold ^^^ this option is not availavle on linux – podarok Oct 6 '15 at 12:30
@podarok It's available on OpenSUSE 13.2 Linux. Try to find a more recent version of your distribution or compile a more recent version of the package yourself. – Aaron Digulla Oct 7 '15 at 8:51
It doen't work on Ubuntu LTS (14.04). It is the most recent one )) – podarok Oct 7 '15 at 13:16
@podarok Which version of GNU coreutils? Mine is 8.24. – Aaron Digulla Oct 8 '15 at 7:33
Caching might have been a bad term. I was thinking of something like done in this port where we scan the disks contents once into a mapping and then continue using data from that mapping rather than hitting the disk again. – Hennes Jan 12 at 14:09

Be aware, that you can't compare directories with du on different systems/machines without getting sure, both share the same blocksize of the filesystem. This might count if you rsync some files from a linux machine to a nas and you want to compare the synced directory on your own. You might get different results with du because of different blocksizes....

share|improve this answer

You might also want to check out xdiskusage. Will give you the same information, but shown graphically, plus allows to drill down (very useful). There are other similar utilities for KDE and even Windows.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .