Is it possible to 'instantly' create arbitrary files?

I've seen the following trick to create large, empty files somewhat quickly:

dd if=/dev/zero of=test.dat bs=1024 count=1024

However, this still takes some time when creating multi-GB files. I presume this time is dominated by the disk writing all the \0s from /dev/zero to test.dat.

Is there any way to "instantly" create a file of arbitrary size, without actually initializing its contents to anything?


Yes, if your filesystem supports sparse files.

Your dd method actually creates the files and fills the created file with zero's. It actually has to write those zeros and that takes time.

If you 'skip' ahead in the file without writing you will still create a seemingly large file, without actually writing to the file. Since this large file does not consume actually disk space it is even possible to create files larger than the FS it is on allows.

If you want to try this, use something like this
dd seek=123456 if=/dev/null of=sparse-file bs=1M

(Take care with backups and restores with software which is unaware of sparse files).