Server Fault is a question and answer site for system and network administrators. 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

Since the beginning the standard UNIX/Linux systems support sparse files, this is a file which contains unused space that is unallocated until needed. To review, to generate via a C program: create a file, position to 2G, write ONE byte, close file. Doing an ls -l shows the size to be 2G....however ls -ls shows the size in blocks to be closer to a one byte file. If you logically access the file (i.e. cp sparse_file xxx) the resulting file xxx will indeed contain a fully allocated 2Gbytes.

I have created sparse files in the past as a testing vehicle for some of applications. However, their existence has caused a few problems.

The important problem is that outside of the 'dump' program, backup programs and general procedures access these type of files logically and thus for a 1 byte sparse file one gets a backup w/ 2G of 0'd data. This has caused some upset backup folks when I do this.

Any good solutions for this type of situation?

share|improve this question
sorry I mispelled Linux in the title. :-( – mdpc Aug 14 '09 at 1:23
Pro Tip: You don't need a custom program to create a sparse file, just dd: "dd if=/dev/zero of=sparse bs=1G seek=2 count=0". – MikeyB Aug 14 '09 at 4:30
or "truncate -s 1G sparse" – Pontus Sep 1 '10 at 18:41
up vote 3 down vote accepted

GNU Tar has the --sparse (-S) options that make working with spares files simple.

share|improve this answer

Use a backup program that is capable of detecting and handling sparse files correctly. There's plenty of them around (a la Jeremy's suggestion of tar with -S), just make it a checklist item on your backup system evaluation.

share|improve this answer

rsync-based backup programs should be able to handle space files just fine (rsync has --sparce/-S options)

share|improve this answer

The star program is much faster for sparse files than GNU tar. It requires the -sparse option when handling such files. For just plain copying use cp --sparse=auto

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.