Generate dummy files in bash

You can try head command:

$ head -c 100000 /dev/urandom >dummy

You may use dd for this purpose:

dd if=/dev/urandom bs=1024 count=5 of=dummy
  • if:= in file
  • of:= out file
  • bs:= block size

Note, that

 x=`expr $x + 1`;

isn't the most efficient way to calculation in bash. Do arithmetic integer calculation in double round parenthesis:

 x=((x+1)) 

But for an incremented counter in a loop, there was the for-loop invented:

x=0;
while [ $x -lt 100000 ];
do echo a >> dummy.zip;
  x=`expr $x + 1`;
done;

in contrast to:

for  ((x=0; x<100000; ++x))
do
    echo a 
done >> dummy.zip 

Here are 3 things to note:

  • unlike the [ -case, you don't need the spacing inside the parens.
  • you may use prefix (or postfix) increment here: ++x
  • the redirection to the file is pulled out of the loop. Instead of 1000000 opening- and closing steps, the file is only opened once.

But there is still a more simple form of the for-loop:

for x in {0..100000}
do
    echo a 
done >> dummy.zip