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 ? |
dd if=/dev/zero of=filename bs=567 count=1
|
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....;)) |
Many thanks !
|
Quote:
|
Quote:
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. |
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. |
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. |