2019-10-07 :: 1 min to read
§ Useful bash tips & tricks and functions

This stuff can be added to .bashrc and used in everyday MacOSX development. Some of the tips are organised already in the my dotfiles repo.

Random string

random-string()
{
    cat /dev/urandom | env LC_CTYPE=C env LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n ${1:-1}
}

then

$ random-string 10 4
hXJJAmt0dE
6y4mYlZ3A4
TAffXSRFfR
cHKcQTPXZj

Java-like UUID

alias uuidgen='uuidgen | tr "[:upper:]" "[:lower:]"'
$ uuidgen
e66413af-f855-4568-944b-8d3175053672

Timestamp

alias ts='date +%s'
$ ts
1570480900
#bash#shell#tips