I recently discovered this method for generating a 9 character password from the linux prompt in bash:
< /dev/urandom tr -dc A-Za-z0-9_ | head -c9
What is < doing?
|
|
In case you're wondering, this is just a less common usage of the input redirector. The shell takes the file specified as input and its default behavior is to echo it to stdout. The breakdown of the command you have:
The options -dc are equivalent to --delete --complement, which means to delete the complement of the following set of characters, i.e. all characters NOT in the set. That excludes non alphanumeric & underscore characters in your example.
Put it all together and you get, "print me the first 9 alphanumeric or underscore bytes from /dev/urandom". :) |
|||||||
|
|
Try In case you need a program output being given as file, it can be done this way: |
|||||
|