Improving speed on du command on mount point

1.6k views Asked by At

Is there a way to improve speed on du command on mount point?

I am looking to retrieve occupied space of top level directory of a specified directory in bytes with below command on a mount point & I see its super slow.

du -b --max-depth=1 <mountName>

Whereas df on other hand works super fast to retrieve data of mount point.

Would like to know if there is a way to use du on mount point & get required data in a faster way?

Also is there a way to get sub-directory size ( in bytes ) on top level directory using different command on a mount point?

2

There are 2 answers

1
DevSolar On

du traverses the directory tree, while df doesn't. That is why df is so much faster, but also only works on whole partitions -- it just reads that partition's metadata. I don't think there is a way around du being slower.

Also is there a way to get sub-directory size ( in bytes ) on top level directory using different command on a mount point?

du -b -s <mountpoint>/*
0
TuilesPaprika On

I am currently copying several TB from one disk to another. The cp command is running in a screen obviously.

Now, I did not know how to get an idea of the copying progress. du -sh was taking forever, similar to what you are describing. Actually it was so long my SSH session failed everytime because of wifi issues.

So, I ran the du -sh in a screen as well, redirecting the output to a file. I have no idea why, but this fixes the problem, maybe it is caching something. The screen running du exits very fast and after that I can run du -sh and get the result immediatly.