I have a directory ~/D that I'd like to find the size of. using du -c ~/D/* gives 26880. However, if I run ls -l ~/D, then I can clearly see that the individual files add up to much more than 26880. In fact, if I inspect a single file, du get's that wrong as well. The last line of the output of du ~/D/* gives

256 /home/me/D/lastFile.bin

while the last line of ls -l ~/D is

-rw-r--r-- 1 me myGroup 3124 Aug 24 21:58 lastFile.bin

where 256 clearly does not equal 3124. What gives? Does it matter that these are binary files?

Edit: This is not a duplicate of a question regarding the difference between du and df; df does not seem to be able to offer me anything in this situation

Edit: stat -c %s ~/D/lastFile.bin agrees with the output of ls -l


1 Answer 1


From the man page:

   Display values are in units of the first available SIZE from
   --block-size, and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE
   environment variables.  Otherwise, units default to 1024 bytes (or
   512 if POSIXLY_CORRECT is set).

So, 256 kB (or 128 kB, if you happen to be POSIXly-correct) gives plenty of room for a couple of 3124-byte files.

With GNU du, you can use the -B option to set the unit size for the output, either use -B1 or -b (equal to -B1 --apparent-size) to get the size in bytes, which is what ls prints by default.

The mismatches you might actually see may be quirks of the filesystem bookkeeping, at least mostly the fact that files are allocated in full blocks. For example, on an ext4 filesystem, a 100000-byte file actually takes 102400 bytes, since it's allocated in blocks of 4096 bytes. That's what du shows on my system.

--apparent-size makes du count just the data size of the files, not the overhead.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .