4

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.

alper
  • 2,919
  • 9
  • 53
  • 102

2 Answers2

5

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.

gniourf_gniourf
  • 44,650
  • 9
  • 93
  • 104
cb0
  • 8,415
  • 9
  • 52
  • 80
0

This Will Make a 1gb file :

mkfile -n 1g /location/to/folder/
Nate
  • 188
  • 1
  • 11
  • Take a look at this site : http://osxdaily.com/2013/05/31/create-large-file-mac-os-x/ – Nate May 25 '16 at 06:57