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?
Paul Howarth
paul at city-fan.org
Wed Nov 17 11:53:55 UTC 2004
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 at dxr tmp]# echo "(0 `find /home/vj/ -name \* -printf "+%s "`) / 1024" |
> bc
> 29091
>
> [root at dxr tmp]# du -s /home/vj/
> 31883 /home/vj/
>
> Thinking du might be using 1000 as 1Kb rather than 1024, following result is
>
> [root at 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.
More information about the users
mailing list