Quote:
Originally Posted by tantric
Can anyone think of a scenario in which size reported by ls -l is less than the size reported by du.
The other way round is possible, if the file has holes, ls -l will report a size more than du (since du calculates the actual disk usage)
That is pretty much the usual case. Take a McKusick style filesystem with 4k blocks and 1k fragments. I create a file with a single byte. ls says the length is 1 byte. du says the length is 2 blocks.
Here is the definition of a stat structure. ls uses st_size while du uses st_blocks. (ls will report both numbers if you use "ls -ls".) The relationship between these two numbers depends on the filesystem. With most filesystems, yes, indirect blocks count. Some filesystems may have a way to preallocate data blocks to a file in advance of the need.
Btw, your second case is often called "sparse files".