Create files with certain size

What it does:  The script will create certain number of files with certain size. It takes two arguments – first is the number of files and the second is the size of each file ( in kilobytes ).

Usage:  ./ 100 1
(this will create 100 files 1MB each)


while [[ $counter -le $filecount ]];
do echo Copying $counter;
dd if=/dev/zero of=filename$counter bs=$2k count=1024
let "counter +=1";

2 thoughts on “Create files with certain size

  1. livibetter

    I’d prefer using ARITHMETIC EVALUATION:

    while ((counter <= filecount));

    and prefixing 0 to the filenames:

     printf -v filename '%04d' $counter

    and maybe using for for clearer code:

    for ((counter = 1; counter <= filecount; counter++)); do
     do echo Copying $counter
     printf -v filename 'filename%04d' $counter
     dd if=/dev/zero of=$filename bs=${blocksize}k count=1024

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s