generate a random file using shell script

Progress Programmer picture Progress Programmer · Apr 6, 2010 · Viewed 11.2k times · Source

How can i generate a random file filled with random number or character in shell script? I also want to specify size of the file.

Answer

Tadeusz A. Kadłubowski picture Tadeusz A. Kadłubowski · Apr 6, 2010

Use dd command to read data from /dev/random.

dd if=/dev/random of=random.dat bs=1000000 count=5000

That would read 5000 1MB blocks of random data, that is a whole 5 gigabytes of random data!

Experiment with blocksize argument to get the optimal performance.