The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




Thread: ls- l and du
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 04-19-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
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".