How to get a 10-byte length random string in bash

How to get a 10-byte length random string in bash.

Use this script to get a 10-byte string of letters:

tr -dc "[:alpha:]" < /dev/urandom | head -c 10

You can also get a string of letters or numbers:

tr -dc "[:alnum:]" < /dev/urandom | head -c 10

Or printable characters except space:

tr -dc "[:graph:]" < /dev/urandom | head -c 10

Or printable characters including space:

tr -dc "[:print:]" < /dev/urandom | head -c 10
Leave a Reply

Your email address will not be published. Required fields are marked *