Create many files with random content

Source: https://unix.stackexchange.com/questions/199863/create-many-files-with-random-content

 

For example,

Name            size
file1.01        2K
file2.02        3K
file3.03        5K
etc.

 

Strategy – 1

#! /bin/bash
for n in {1..1000}; do
    dd if=/dev/urandom of=file$( printf %03d "$n" ).bin bs=1 count=$(( RANDOM + 1024 ))
done

 

Strategy – 2

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

 

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *