Why ls and du show different size?

23

3

I am downloading a file with rtorrent,

When I check the folder that the file is located on, the filesize with ls command is 4.4GB but when I check the disk with du command it shows me 219MB, also the same problem with df command that seems just calculate the 219MB one.


Here is the my console result

root@SERVER:/home/.root/TMP/tnt/d1/xxx# dir -alh

total 219M
drwxr-xr-x  2 root root 4.0K 2010-01-10 15:30 .
drwxr-xr-x 15 root root 4.0K 2010-01-10 15:30 ..
-rw-r--r--  1 root root 4.4G 2010-01-11 10:55 yyy.mkv

root@SERVER:/home/.root/TMP/tnt/d1/xxx# du -h

219M    .

root@SERVER:/home/.root/TMP/tnt/d1/xxx# 

user24263

Posted 2010-01-11T07:35:56.117

Reputation: 546

I ran across this same problem today after growing a disk image using qemu-img resize. – Pete – 2014-07-30T14:35:47.883

Answers

40

It's a sparse file. ls is reporting the allocated size; du is reporting the amount of space actually used.

As your torrent client downloads more it will fill in the gaps and the du-reported size will grow to match what ls reports.

To force du and df to include sparces, from the man du the second option listed is --apparent-size:

du -s -B1 --apparent-size

James Polley

Posted 2010-01-11T07:35:56.117

Reputation: 5 892