Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a file in linux machine whose size is 3404494030 upon doing "ls -l". When I do "ls -lh" it shows 3.2 GB which is correct when converted from bytes to Gigabytes. But when I do "du -h" for the same file, it shows 4 GB. I have tried on many instances but I have found that there is inconsistency between the output of "ls" and "du". I also tried to see the size of the file using filezilla client (ftp client on windows) by right clicking on the file and monitoring its size through the file properties. The output of "ls" and filezilla matches. I am using CentOS and I am wondering if it is a bug of "du" or is there a problem in my understanding of "du". There is a similar question asked earlier. I checked it and found it to be a trivial question.

share|improve this question

migrated from Nov 26 '12 at 5:23

This question came from our site for professional and enthusiast programmers.

up vote 6 down vote accepted

ls shows space allocated for file.

du shows amount of space actually used by file.

share|improve this answer

Sparse Files:

$ dd if=/dev/zero of=sparse.img bs=1M seek=1024 count=0
$ ls -lh sparse.img
-rw-rw-r-- 1 ruiqi ruiqi 1.0G Nov 26 11:23 sparse.img
$ du sparse.img
0   sparse.img
share|improve this answer
I think my file is not a sparse file. I am not sure whether your example is applicable in my case because for my file "du" shows 4 GB which is greater than the output of "ls" which is only 3.2 GB – justin waugh Nov 26 '12 at 3:56

You must log in to answer this question.