LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   how to create file with a specific file size (https://www.linuxquestions.org/questions/linux-software-2/how-to-create-file-with-a-specific-file-size-578944/)

markraem 08-22-2007 10:21 AM

how to create file with a specific file size
 
I am looking for a tool that can create a file with a specific file size. The content of the file does not matter.

for instance :

[root]#tool-i-am-looking-for filename 567

will create a file called filename with size = 567 bytes.


I know that via touch you can create a file, but it will only create a file with zero bytes length.

does a tool like that exist in linux ?

jiml8 08-22-2007 10:24 AM

dd if=/dev/zero of=filename bs=567 count=1

pixellany 08-22-2007 10:31 AM

dd if=/dev/zero of=newfile bs=1 count=567

"dd" is the ultimate power tool--use with caution!!

Edit--now you have 2 very different methods!!! (We did NOT rehearse this....;))

markraem 08-22-2007 10:47 AM

Many thanks !

jiml8 08-22-2007 11:46 AM

Quote:

Originally Posted by pixellany (Post 2866943)
dd if=/dev/zero of=newfile bs=1 count=567

"dd" is the ultimate power tool--use with caution!!

Edit--now you have 2 very different methods!!! (We did NOT rehearse this....;))

LOL. Not sure, but I think the way I wrote it would be faster.

pixellany 08-22-2007 12:31 PM

Quote:

Originally Posted by jiml8 (Post 2867010)
LOL. Not sure, but I think the way I wrote it would be faster.

I expect you are right--although mine took less than 1 second.

I did it that way because I had first attempted to use /dev/random and was getting strange results---It **appeared** that maybe dd did not like off-beat block sizes.

jiml8 08-22-2007 04:04 PM

jiml@Dadsbox:jiml> time dd if=/dev/zero of=newfile bs=1 count=567
567+0 records in
567+0 records out
567 bytes (567 B) copied, 0.001906 seconds, 297 kB/s
0.00user 0.00system 0:00.04elapsed 20%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (1major+264minor)pagefaults 0swaps
jiml@Dadsbox:jiml> time dd if=/dev/zero of=newfile bs=567 count=1
1+0 records in
1+0 records out
567 bytes (567 B) copied, 8.4e-05 seconds, 6.8 MB/s
0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+266minor)pagefaults 0swaps


Actually, I had wondered what it would do with the "odd sized block" as well, but it didn't seem to care in this case.

pixellany 08-22-2007 06:38 PM

I agree---84 microseconds is a lot faster than 1900 microseconds!!! Doing something like this all day using my method could have cost someone a coffee break......:eek::eek:

All seriousness aside, there's no question that the larger block size is the right answer....


All times are GMT -5. The time now is 06:11 AM.