I’ve tried using du to calculate disk usage today on a single directory. The size of directory is 6GB and it took the following amount of time to calculate:
prompt> time du -sh .
6.0G .
real 1m32.405s
user 0m2.053s
sys 0m16.552s
What is the algorithm unix du command uses to calculate disk space? Why is it so slow? Are there any alternatives to calculate disk space more efficiently? The platform of invocation is Sun. The directory for which size was calculated is NFS mounted.
I think it just recursively walks the directory, while adding together the sizes of the files found. Quite simple, really, but of course it takes time. It might be faster if the file system makes these operations quicker.