Sponsored Content
Full Discussion: ls- l and du
Top Forums UNIX for Dummies Questions & Answers ls- l and du Post 302114964 by Perderabo on Thursday 19th of April 2007 08:35:24 PM
Old 04-19-2007
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".
 
All times are GMT -4. The time now is 03:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy