I can't figure out why I'm getting the following results:
ls -l
tells me the size of a given file (HISTORY) is "581944":
$ ls -l HISTORY
-rw-rw-r-- 1 waldyrious waldyrious 581944 Feb 22 10:59 HISTORY
ls -s
says it is "572":
$ ls -s HISTORY
572 HISTORY
I obviously need to make the values use a comparable scale. So first I confirm that using --block-size 1
in ls -l
gives me the same result as before:
$ ls -l --block-size 1 HISTORY
-rw-rw-r-- 1 waldyrious waldyrious 581944 Feb 22 10:59 HISTORY
Then I do the same to ls -s
to get a value in the same scale:
$ ls -s --block-size 1 HISTORY
585728 HISTORY
Different results! 581944 ≠ 585728.
I tried generating comparable values the other way around, using -k
, but I get:
$ ls -lk HISTORY
-rw-rw-r-- 1 waldyrious waldyrious 569 Feb 22 10:59 HISTORY
$ ls -sk HISTORY
572 HISTORY
Again, different results, 569 ≠ 572.
I tried specifying --si
to make sure both options were using the same scale, to no avail:
$ ls -lk --si HISTORY
-rw-rw-r-- 1 waldyrious waldyrious 582k Feb 22 10:59 HISTORY
$ ls -sk --si HISTORY
586k HISTORY
...again, different values: 582k ≠ 586k.
I tried searching the web but the only thing I could find that seemed relevant was this:
Some files have "holes" in them, so that the usage listed by
ls -s
(...) is less than the file size listed byls -l
."
(note that in my results the opposite happens: ls -s
returns sizes bigger than ls -l
, not smaller.)
Meanwhile, this page says that
there is no elegant way to detect Unix file holes.
So, how can I deal with this discrepancy? Which of these values can be considered correct? Could this possibly be a bug in ls
?
ls -s
count that? – Flimm Mar 19 '13 at 18:05sudo tune2fs -l /dev/sdaX|grep Inode
, ordf -i
for all partitions. – phoibos Mar 19 '13 at 19:29ls -lsh ~/Downloads/torrents
gives me, for example,92K -rw-r--r-- 1 waldir waldir 350M Sep 15 2012 video.avi.part
. That is, the 92K, returned by the -s option, is the actual space the file takes, filesystem-wise, and 350M, returned by the -l option, is the full size the file would have if it was completely downloaded (i.e. if all the bytes, from start to finish, were non-zero). See http://lists.freebsd.org/pipermail/freebsd-questions/2012-June/242207.html – waldyrious Mar 27 '13 at 13:57