Question

I need to be able to create a large number of files, randomly-sized 1k-64k averaging 32k, very quickly. One method I've found uses the unix command dd to copy bytes from /dev/urandom into a new file. However, I'm trying to save the time by just creating the file link to unallocated space, without writing random bytes to disk.

Is this possible in a Unix-like environment and, if so, how would I go about it?

If not, could this be done with a small C program?

Was it helpful?

Solution

From the commandline, mkfile or dd or any number of other (not-necessarily POSIX-standard) utilities. I would note that copying from /dev/zero instead of /dev/urandom can be significantly quicker, especially on older systems with slower CPUs.

If you want to do something in C or C++ code, there's truncate() and ftruncate(). Probably most Perl/Python/whatever bindings expose the system/libc call in some way as well.

OTHER TIPS

So you want to mkfile {size}[b|k|m|g] filename in cwd?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top