Modular Computers the manual GitHub

mktemp

mktemp: make a file or directory with a unique name.

Synopsis

mktemp [-d] [-p dir] [-t] [template]

Description

mktemp makes a new, empty file (or, with -d, a directory) with a name nothing else has, and prints its name.

The trailing Xs of template (there must be at least 3) are replaced by random letters and digits; names are tried until one is free (up to 100 tries). With no template, tmp.XXXXXXXXXX is used, in the directory given by -p, else in $TMPDIR or, if that is not set, /tmp. A template that is given is taken as a path from the current directory, unless -p or -t names a directory for it.

Options

-d
Make a directory, not a file.
-p dir
Put a template that has no / in dir.
-t
Put a template that has no / in $TMPDIR or /tmp.

Exit status

0 on success; 1 on a bad option, too few Xs, or if nothing could be made.

Examples

f=$(mktemp)
dir=$(mktemp -d)
mktemp -t build.XXXXXX

Notes

There is no -u or -q.

See also

mkdir(1), touch(1), rm(1)