Weird question... Fastest way to create large arbitrary files?
Often I find myself running tests (such as transfer speed) where I need large files as testers. Doesnt matter whats in them... just use them for the data transfer or whatever.
Normally I do a: head -c SIZE /dev/urandom > filename where SIZE is the size of the file I need in bytes. The problem is that for files over a few megs this method is slow because you have to wait on the machine to fill it with random information. So my question... Is there a way to create files of arbitrary sizes instantly. Like... some way to manipulate the file descriptor so that a file is allocated a large amount of space. ??? Someone told me there is a way.. but I have no idea. Thanks :) |
[root@jebus root]# time head -c 100000000 /dev/zero >filename
real 0m2.174s user 0m0.090s sys 0m0.830s [root@jebus root]# P3 1ghz machine w/256 MB ram. |
awesome!
thats fast enough... what is /dev/zero? :) :) |
It's one of those "black hole" special files. If you use it to make a ten meg file, then try to cat that file, you'll see that there's not a damn thing in the file.
Think of it as a filesize BS machine. :) |
takes about 30 secons for a gig file on my dual processor machine.
I wonder if there is a way to just manipulate a file so this process can be instant? |
If you want the process to be instant, why don't you just create the huge file(s) once, then not delete it? Sure, you'll waste a chunk a space, but since it sounds like this activity is something you do frequently, why not save yourself the trouble of having to create these bogus files each time. -- J.W.
|
because thats not an interesting solution :)
And a sysadmin told me it was possible but not obvious. (and he couldnt remember either) |
A fair enough assessment. At the same time though, which is better: A non-interesting solution that actually works exactly the way you want it to, or spending a lot of time trying to track down rumors about a potentially faster solution, which few people, if any, seem to be able to recall? -- J.W.
|
they have actually done it for some project.. ill make him look it up and ill post the solution :)
for now doing a head on /dev/zero is pretty darn good :) |
FWIW, I believe /dev/zero is actually the writing of zero's to the HD.
Cool |
All times are GMT -5. The time now is 10:59 AM. |