I have searched a lot but couldn't find a solution for this.
Insida a folder, how could I create random files and folders that will be size of in 1M, 10M, 100M, 1G, 10G. Each created folders also needs to have a randomly created file in it.
You could use dd
with different file sockets, e.g. /dev/random
or /dev/zero
.
This will create a 2MB file with random data in it:
dd if=/dev/urandom of=file.out bs=1M count=2
Or create a 1MB file from /dev/zero
:
dd if=/dev/zero of=file.out bs=1024 count=0 seek=1024
There are a lot of examples out there, just search for "linux dd create file size". This should be wrapped in a script that will create the directories and files for you. I would think of something like this.
#!/bin/bash
#create files of 1, 10, 100 and 1000MB in size
for fSize in 1 10 100 1000
do
#create a file for size 1MB*fSize
dd if=/dev/zero of=file.out bs=1024 count=0 seek=$((1024*fSize))
done
Combined with another script that will create the directories and another fSize
loop it should do what you want.