`ls -l` shows size of file other than of the folder?

David Tilbrook dmtilbrook at gmail.com
Thu Jun 14 00:18:42 UTC 2012

What you have are sparse files.  The size listed by ls -l is the
length of the files as if all the file from start to end contain data,
but unix allows one to seek beyond the end of a file and add more data,
thus leaving unused blocks.  A common example of sparse files
is the *.pag file in a dbm database as created by Ken (Thompson).

The ls -s flag will show you how many real blocks are used.

The program stat(1) will also show you the number of blocks used.

The following creates a file with a size of 1024000002 (a gig),
that actually contains only 2 chars.

#include	<stdio.h>
	fwrite("a", 1, 1, stdout);
	fseek(stdout, 1000000*1024, SEEK_END);
	fwrite("b", 1, 1, stdout);

cc foo.c ; ./a.out > ,z ; ls -ls ,z

You can od ,z

Old codger story from the distant past (circa 1975):

When we were using rk05s as our disks, we had to watch
for programs that used to fill-in the holes as we often
had files that had sizes that were bigger than the amount
of storage on an rk05  (5 Meg).  Yes people used to live
that way.

>From the not so distant past (1985): The Andrew File system
at CMU used to fill in the holes as it copied files from the
file servers to the local host, and back again -- ycccch.

-- david

On Wed, Jun 13, 2012 at 4:23 PM, Peter Vereshagin <peter at vereshagin.org> wrote:
> Hello.
> I have the directory in the file system with 2 regular files each  of  which  is
> sized as 700M according to 'ls -l'.  But the torrent client and 'du -s' and  'ls
> -l's 'total' show that the directory size is 300M.
> How can that be?  Are there different file sizes  stored  on  a  ufs1  in  their
> metadata?
> ot the least how could I see the 'real' size of each of those files, both  ~150M
> actulally, with a system command?
> Thank you.
> --
> Peter Vereshagin <peter at vereshagin.org> (http://vereshagin.org) pgp: A0E26627
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"

More information about the freebsd-questions mailing list