Date: Wed, 13 Jun 2012 20:18:41 -0400 From: David Tilbrook <dmtilbrook@gmail.com> To: Peter Vereshagin <peter@vereshagin.org> Cc: freebsd-questions@freebsd.org Subject: Re: `ls -l` shows size of file other than of the folder? Message-ID: <CAAPNFHQVu2q9ij%2BP5%2BtOZOVURsVL_y1zgC1P3pxoyof9h2=wYw@mail.gmail.com> In-Reply-To: <20120613202325.GC5800@external.screwed.box> References: <20120613202325.GC5800@external.screwed.box>
next in thread | previous in thread | raw e-mail | index | archive | help
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>
main()
{
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@vereshagin.org> wr=
ote:
> Hello.
>
> I have the directory in the file system with 2 regular files each =A0of =
=A0which =A0is
> sized as 700M according to 'ls -l'. =A0But the torrent client and 'du -s'=
and =A0'ls
> -l's 'total' show that the directory size is 300M.
>
> How can that be? =A0Are there different file sizes =A0stored =A0on =A0a =
=A0ufs1 =A0in =A0their
> metadata?
>
> ot the least how could I see the 'real' size of each of those files, both=
=A0~150M
> actulally, with a system command?
>
> Thank you.
>
> --
> Peter Vereshagin <peter@vereshagin.org> (http://vereshagin.org) pgp: A0E2=
6627
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.o=
rg"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAAPNFHQVu2q9ij%2BP5%2BtOZOVURsVL_y1zgC1P3pxoyof9h2=wYw>
