Create files with random sizes with only bash and dd
So you need a bunch of files of random size. Say something between 1 MiB and 10 MiB. And you need 3 of them.
bash to the rescue.
- The variable
$RANDOMwill return an integer between 0 a nd 32,767.
$((...))will do arithmetic expansion for the expression contained within
%-operator will do a modulo operation
Let me use those 3 simple rules to create
- 3 files between 1 MiB and 10 MiB
- 3 files between 15 MiB and 25 MiB
As a side note: I will be creating sparse files here. Look up
dd(1) for the details. Your use case might be different anyway.
1 MiB -- 10 MiB files
15 MiB -- 25 MiB files
The result looks quite good.
Yes I know this is minor math at best. But still I tend to forget that problems like this are easily solveable, so I'll not it down here. And yes, there's probably a bunch of cases where bash isn't what you want to use. I needed lots of files to test mdadm behaviour so that I can use them as disks and create RAID arrays.Server!/Horror