Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random file generator code?

Tags:

random

Does anyone have a simple shell script or c program to generate random files of a set size with random content under linux?

like image 272
hookenz Avatar asked Dec 01 '22 05:12

hookenz


2 Answers

How about:

head -c SIZE /dev/random > file
like image 131
Carl Norum Avatar answered Dec 27 '22 20:12

Carl Norum


openssl rand can be used to generate random bytes. The command is below:

openssl rand [bytes] -out [filename]

For example,openssl rand 2048 -out aaa will generate a file named aaa containing 2048 random bytes.

like image 45
onemouth Avatar answered Dec 27 '22 19:12

onemouth