Quickly Create 100 Thousand Random Files In a Folder Linux

This command very quickly creates 100k randomly sized binary files in the directory you run it in. Took 6 minutes 37 seconds to run on Amazon micro ec2 instance.

time seq -w 1 100000 | xargs -n1 -I% sh -c 'dd if=/dev/urandom of=file.% bs=$(shuf -i1-10 -n1) count=1024'

Output (end only)

4096 bytes (4.1 kB) copied, 0.00239389 s, 1.7 MB/s
1024+0 records in
1024+0 records out
10240 bytes (10 kB) copied, 0.00245996 s, 4.2 MB/s
1024+0 records in
1024+0 records out
3072 bytes (3.1 kB) copied, 0.0024165 s, 1.3 MB/s
1024+0 records in
1024+0 records out
3072 bytes (3.1 kB) copied, 0.00240838 s, 1.3 MB/s

real 6m37.352s
user 0m25.895s
sys 5m48.173s

Leave a Reply

Your email address will not be published.