Bash/Misc/Random string

Aus SchnallIchNet
Wechseln zu: Navigation, Suche

generate a random string

l=20
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs echo

this generates a 20 bytes log pseudo(!!)-random string.
this will help you to generate more or less secure passwords

if included in bashrc as a function you may use it as a command in bash:

genpasswd() {
   local l=$1
   [ "$l" == "" ] && l=20
   tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}