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

What is the difference between these two:

du -h --max-depth=2 /usr/* | sort -nr | head -n 20

And:

du -h --max-depth=2 /usr/ | sort -nr | head -n 20

I would like to display the 20 biggest folder under /usr folder.
Does this 20 folder includes the overall subfolders sizes as well ?

share|improve this question
up vote 7 down vote accepted

There are some important changes in the behavior of these two invocations. Let's use an example, with the structure created by:

mkdir mydir/{.a1,a2,a3}/{.b1,b2}/{.c1,c2} -p

If you invoke du --max-depth=2 mydir you will get:

0       mydir/.a1/.b1
0       mydir/.a1/b2
0       mydir/.a1
0       mydir/a2/.b1
0       mydir/a2/b2
0       mydir/a2
0       mydir/a3/.b1
0       mydir/a3/b2
0       mydir/a3
0       mydir/

But if you run:

du --max-depth=2 mydir/*`

the wildcard character will be expanded and it will become an equivalent of:

du --max-depth=2 mydir/a2 mydir/a3

which will give you the following result:

0       mydir/a2/.b1/.c1
0       mydir/a2/.b1/c2
0       mydir/a2/.b1
0       mydir/a2/b2/.c1
0       mydir/a2/b2/c2
0       mydir/a2/b2
0       mydir/a2
0       mydir/a3/.b1/.c1
0       mydir/a3/.b1/c2
0       mydir/a3/.b1
0       mydir/a3/b2/.c1
0       mydir/a3/b2/c2
0       mydir/a3/b2
0       mydir/a3

The important thing to note here is that it will omit the .a1 directory. In order to include it you would have to run something similar to: du --max-depth=2 mydir/{.[!.]*,*} (but I guess there might be an easier and more generic way that I don't know of). It will also not calculate the overall size of the mydir directory.

And yes, the sizes reported by du include sizes of the subfolders.

share|improve this answer

The former counts visible objects within /usr. The latter counts all objects under /usr, including /usr itself.

share|improve this answer

You must log in to answer this question.

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