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:


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?

  • "a single word of length"? Of length what? The only limit you address is the file size, if the random word has that length, there will be only one line. Your post doesn't make sense, please update it how you propose to invoke the command to create what you want and (a snippet) of the output file.
    – Anthon
    Apr 15, 2016 at 6:25
  • I have said in my question that 'word of length within the specified limit' . There are two arguments here, first is the file size which can be 1M, 1G or whatever and the second one is the limit of the word length which can be 1 to whatever specified.
    – Punit Naik
    Apr 15, 2016 at 6:29

1 Answer 1


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.

  • Your interpretation of my question is spot on. However when I tried to run your command it said "fold: invalid option -- 'c'".
    – Punit Naik
    Apr 15, 2016 at 6:40
  • @PunitNaik you may try fold -b10, also see fold --help for options. fold -c10 works for me, i'm using SUSE. which OS are you using? Apr 15, 2016 at 6:42
  • I am using ubuntu. -b option worked though. Only one thing, /dev/random hung when I executed the program. But when I cahnged from random to urandom, it worked like a charm. Do you care to change it so that I can accept your answer?
    – Punit Naik
    Apr 15, 2016 at 6:43
  • 1
    cat /dev/urandom may work better too. /dev/random just hung on my laptop. Apr 15, 2016 at 6:49
  • 1
    /dev/random will block when it runs out of entropy, /dev/urandom will not (and works just fine for 99% of cases)
    – tgharold
    Apr 15, 2016 at 12:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .