LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Weird question... Fastest way to create large arbitrary files? (https://www.linuxquestions.org/questions/linux-software-2/weird-question-fastest-way-to-create-large-arbitrary-files-89710/)

wizade 09-05-2003 05:41 PM

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 :)

Saraev 09-05-2003 05:50 PM

[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.

wizade 09-05-2003 06:10 PM

awesome!

thats fast enough...

what is /dev/zero?

:) :)

Saraev 09-05-2003 06:12 PM

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. :)

wizade 09-05-2003 07:01 PM

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?

J.W. 09-06-2003 01:32 AM

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.

wizade 09-06-2003 02:27 AM

because thats not an interesting solution :)

And a sysadmin told me it was possible but not obvious. (and he couldnt remember either)

J.W. 09-06-2003 02:38 AM

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.

wizade 09-06-2003 03:05 AM

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 :)

MasterC 09-06-2003 03:37 AM

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.