[SOLVED] Generate A Random Character Text File through CLI

Hey Everyone,

New here, figured this would be the place to get the quickest response. I am needing to find a way to create a .txt file with several equal length lines of randomly generated characters.

Here is a shell command I found through my attempts to google an answer.

"$ < /dev/urandom tr -dc "[:alnum:]" | head -c100 > file.txt"

The problem with this particular command is that it only creates one line, or multiple lines that are uneven when "\n" is added.

I am very new to linux, and would be happy to look through man pages or find the answer myself but I am not sure what shell command to search or what the best way to go about tackling this situation.

1 Like

$ for i in $( seq 1 5); do < /dev/urandom tr -dc "[:alnum:]" | head -c100; echo; done > file.txt

1 Like