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

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

asked Sep 3, 2013 by anonymous

1 Answer

 
Best answer

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
answered Sep 3, 2013 by anonymous
selected Sep 3, 2013

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...