Generate dummy files in bash

jabal picture jabal · Mar 21, 2012 · Viewed 31.6k times · Source

I'd like to generate dummy files in bash. The content doesn't matter, if it was random it would be nice, but all the same byte is also acceptable.

My first attempt was the following command:

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

The problem was its poor performance. I'm using GitBash on Windows, so it might be much faster under Linux but the script is obviously not optimal.

Could you suggest me a quicker and nice way to generate dummy (binary) files of given size?

Answer

kev picture kev · Mar 21, 2012

You can try head command:

$ head -c 100000 /dev/urandom >dummy