ls -l and du -k report very different size for same file

From: Charles Vachon <cvachon_at_mrn.gouv.qc.ca>
Date: Fri, 03 Apr 1998 16:23:19 -0500

Hello DU managers,

Doing a little bit of housekeeping on a DU 4.0b server I newly
administrate, I encoutered a few files right off the root directory (an
ADVFS filesystem). These files consist of only binary zeroes (nulls), and
I'm told they are of no use anymore. I was about to delete these when I
found something strange:

ls -l 4* reports files of multi-megabyte size :

-rw------- 1 root daemon 10469376 Dec 23 1996 41988
-rw------- 1 root daemon 8806400 Dec 23 1996 44330

but du reports very different sizes for these same files:

du -k 4* gives:

8 41988
8 44330

du reports a consumption of only 8 1024-bytes blocks for the same files!

I did an experiment with one of these files. I did a "cat 44330 one >
44444", where one is a file containing a single byte. This created a 44444
file with characteristics one would expect:

ls -l 44444 gives:
-rw-r--r-- 1 root system 8806401 Apr 3 14:33 44444

and du -k 44444 says:
8608 44444

both commands report a consistent file size, since 8608 1024-byte blocks is
roughly the same size as 8806401 bytes.

I figured that maybe there is a special way to treat files in DU/ADVFS
which are containing all nulls. So I did another experiment:
"dd if=/dev/zero of=/tmp/test.file bs=1024 count=50". This creates an
all-nulls files of 51200 bytes:

-rw-r--r-- 1 root system 51200 Apr 3 15:04 test.file

du -k reports a block count consistent with this file size, even though it
contains only nulls:

50 effa.cv1

I'm at a lost trying to explain what I see. Does anyone have an idea of
what could explain this discrepancy?

Thanks in advance!
--
Charles Vachon -- Administrateur de système
Fonds de la réforme cadastrale du Québec
Ministère des Ressources Naturelles du Québec
cvachon_at_mrn.gouv.qc.ca
Received on Fri Apr 03 1998 - 23:30:00 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:37 NZDT