Bash – Create a file of fixed size with specific contents

bashcommand linefilesio

I want to create a file of fixed size (1G, 10G, 100G etc) with a single random word of length within the specified limit on every line. I basically want this to run a benchmark which will sort the entire file.

So if I want a file of 1G and the word length limit is suppose 4, the sample of file would look like this:

a
bc
def
ghij

Here the words' length will be within 1-4 and it won't exceed 4 and this file will eventually have the size of 1G

NOTE: The word can be of a fixed size too. It won't be a problem.

How will I be able to do this?

Best Answer

My understanding of the question is that, you need to create a large file, each line of this file is a random word within specified length.
If you don't need the word to be a real word, but some random characters:

< /dev/urandom tr -d -c '[:alpha:]'|head -c 1M|fold -w10 >result.txt  

This will create a file of size 1M and each line with 10 random characters.

Related Question