In Linux, you can create a temporary file using the mktemp command.
Create temporary file
To create a temporary file using mktemp command, you need to supply the path and the X template. The number of Xs template represent the length of the random name. But, you need at least 3 Xs.
mktemp /tmp/my-script.XXXXXX # /tmp/my-script.ycOanK
Create temporary directory
Using the same principle as creating a temporary file, you add the -d option to the mktemp command.
mktemp -d /tmp/my-temp-dir-XXXXXX # /tmp/my-temp-dir-KdQmhE