Random String in Shell

By Susam Pal on 26 May 2021

Here is a quick way to generate a random alphanumeric string in the shell:

LC_CTYPE=C tr -dc '[:alnum:]' < /dev/urandom | head -c 20; echo

Here is an example output:

$ LC_CTYPE=C tr -dc '[:alnum:]' < /dev/urandom | head -c 20; echo
T1WK1ni9BcWAr0cR44VA
Comments | #unix | #technology