Create large files

Hi,

I need to do some testing and I'd like to be able to create large files of different sizes quickly.
I used to use mkfile for such tasks, but I found that it's not maintened anymore and thus removed.

Is there another util/pkg that I can use to create a large file (1G, 1T...) quickly?
I'm really sad because mkfile could just do that in a second, and there was the option to create an empty file too, so the size was noted but blocks weren't allocated.
If possible I'd like to avoid dd: not only it's slower, but it cannot create an empty file (if needed).

Thanks in advance!
 
What are you trying to test?

Judging from your description, you want files that have a large size attribute, but that do not use much space ("are written in a second"), and that blocks are not allocated. In that case, the truncate command is your friend.

You need to distinguish between sparse files and empty files. An empty file is one that has a size of zero bytes (and therefore also no blocks allocated to it). A sparse file is one that has a size that is larger than the total of allocated blocks. You create sparse files either by seeking to different positions before writing, or by calling the various forms of the truncate() system call (which is a system call, not a utility program, but the truncate utility is mostly a thin wrapper around the system call).

dd is perfectly capable of creating sparse file, if you use the oseek option. For example, to create a file that is 1 TiB of sparseness (meaning unwritten empty space) followed by 1 MiB of zeroes, use this command: "dd if=/dev/zero of=/tmp/foo bs=1048576 count=1 oseek=1048576". It will first skip by 1 million blocks of size 1 MiB on the output (which puts it at the 1 TiB mark), then write a single 1 MiB block of zeroes. On my machine, this takes 4 milliseconds.
 
To create a non-sparse file you can use "dd if=/dev/random"
But as measurement of "speed" it is not so good as it depends on the production of random.
 
Thank you to everyone!
I tried and truncate works like a charm!

I'm just trying some weird raidz configurations, and I'm doing that with many HDD + some files (since I don't have time to actually hook up that many HDD).
I know that making a pool with files is wrong, but for testing, sometimes, it's actually really nice to be able to do it.

Anyway, thank you again for the help.
 
Back
Top