Re: Can anybody explain the difference in the disk usage of a directory by du and the one calculated by adding up the size of every file?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



VJ wrote:
    Can anybody explain the difference in the disk usage of a directory by
du and the one calculated by adding up the size of every file?

[root@dxr tmp]# echo "(0 `find /home/vj/ -name \* -printf "+%s "`) / 1024" |
bc
29091

[root@dxr tmp]# du -s /home/vj/
31883   /home/vj/

Thinking du might be using 1000 as 1Kb rather than 1024, following result is

[root@dxr tmp]# echo "(0 `find /home/vj/ -name \* -printf "+%s "`) / 1000" |
bc
29790

Disk space is allocated in blocks (typically 1K) so you need to round up the size of each file to the next round 1K to get the actual size.


This is not taking into account "sparse" files, which are written by "seeking" to some point in a file (say 1M) and then writing some data (say 1K). The size of such a file reported by ls will be just over 1M but it will only take up 1K of disk space. You're unlikely to have a file like that in your home directory though.

Paul.


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux