Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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