writing large files quickly

Thomas Bellman bellman at lysator.liu.se
Sun Jan 29 08:01:47 EST 2006


Grant Edwards <grante at visi.com> writes:

> $ dd if=/dev/zero of=zeros bs=64k count=1024
> 1024+0 records in
> 1024+0 records out
> $ ls -l zeros
> -rw-r--r--  1 grante users 67108864 Jan 28 14:49 zeros
> $ du -h zeros
> 65M     zeros

> In my book that's 64MB not 65MB, but that's an argument for
> another day.

You should be aware that the size that 'du' and 'ls -s' reports,
include any indirect blocks needed to keep track of the data
blocks of the file.  Thus, you get the amount of space that the
file actually uses in the file system, and would become free if
you removed it.  That's why it is larger than 64 Mbyte.  And 'du'
(at least GNU du) rounds upwards when you use -h.

Try for instance:

    $ dd if=/dev/zero of=zeros bs=4k count=16367
    16367+0 records in
    16367+0 records out
    $ ls -ls zeros
    65536 -rw-rw-r--  1 bellman bellman 67039232 Jan 29 13:57 zeros
    $ du -h zeros
    64M     zeros

    $ dd if=/dev/zero of=zeros bs=4k count=16368
    16368+0 records in
    16368+0 records out
    $ ls -ls zeros
    65540 -rw-rw-r--  1 bellman bellman 67043328 Jan 29 13:58 zeros
    $ du -h zeros
    65M     zeros

(You can infer from the above that my file system has a block
size of 4 Kbyte.)


-- 
Thomas Bellman,   Lysator Computer Club,   Linköping University,  Sweden
"There are many causes worth dying for, but  !  bellman @ lysator.liu.se
 none worth killing for."         -- Gandhi  !  Make Love -- Nicht Wahr!



More information about the Python-list mailing list