How to Populate a File with Random Data

random

How can I create a new file and fill it with 1 Gigabyte worth of random data? I need this to test some software.

I would prefer to use /dev/random or /dev/urandom.

Best Answer

On most unices:

head -c 1G </dev/urandom >myfile

If your head doesn't understand the G suffix you can specify the size in bytes:

head -c 1073741824 </dev/urandom >myfile

If your head doesn't understand the -c option (it's common but not POSIX; you probably have OpenBSD):

dd bs=1024 count=1048576 </dev/urandom >myfile

Do not use /dev/random on Linux, use /dev/urandom.

Related Question