I have an alias in my server's /etc/profile
which generates a random directory on command, like this:
alias rdir="mkdir -p ./`cat /dev/random | tr -cd 'a-z0-9' | head -c 8`/"
But it turns out this generates always the same string (in this case: directory). I figured out already this seems to be related to source
'ing the profile file and only generates a new random string after I call source /etc/profile
.
Now, I wonder, how do I generate a random string in an alias which always changes when I call the alias, like in this example: rdir
? (Without re-source
-ing?)
/dev/urandom
instead of/dev/random
. – cuonglm Jul 21 '15 at 8:17mktemp --tmpdir=. -d XXXXXXXX
? It would even check against existing folders an make sure it is a new directory. – Fiximan Jul 21 '15 at 8:51