Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to create an empty file based on the remaining hard disk space. The problem is that when I create a file that is 1 GB large, the df command shows the remaining space to be only 12 kb smaller than it was before the file was created.

someone@here:/tmp/delete# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             36827144   5031592  29924788  15% /
tmpfs                   508508         0    508508   0% /lib/init/rw
varrun                  508508       156    508352   1% /var/run
varlock                 508508         4    508504   1% /var/lock
udev                    508508       140    508368   1% /dev
tmpfs                   508508      1108    507400   1% /dev/shm

someone@here:/tmp/delete# dd if=/dev/zero of=tempFile bs=1000 count=1 seek=1000000
1+0 records in
1+0 records out
1000 bytes (1.0 kB) copied, 0.000438915 s, 2.3 MB/s

someone@here:/tmp/delete# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             36827144   5031604  29924776  15% /
tmpfs                   508508         0    508508   0% /lib/init/rw
varrun                  508508       156    508352   1% /var/run
varlock                 508508         4    508504   1% /var/lock
udev                    508508       140    508368   1% /dev
tmpfs                   508508      1108    507400   1% /dev/shm

Does anyone know why the df command doesn't account for the full 1GB? Thanks.

share|improve this question
up vote 13 down vote accepted

You created it on a filesystem that supports sparse files so it actually only takes up 1000 bytes, just as the output from dd says. Omit seek and use a proper count.

share|improve this answer

From info coreutils du (emphasis mine):

'--apparent-size'
Print apparent sizes, rather than disk usage. The apparent size of a file is the number of bytes reported by 'wc -c' on regular files, or more generally, 'ls -l --block-size=1' or 'stat --format=%s'. For example, a file containing the word `zoo' with no newline would, of course, have an apparent size of 3. Such a small file may require anywhere from 0 to 16 KiB or more of disk space, depending on the type and configuration of the file system on which the file resides. However, a sparse file created with this command:

dd bs=1 seek=2GiB if=/dev/null of=big

has an apparent size of 2 GiB, yet on most modern systems, it actually uses almost no disk space.

share|improve this answer
    
Huh, sparse files. Excellent for VM images :). – sinni800 Feb 2 '11 at 11:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .