mktemp(1)mktemp(1)Namemktemp - make a name for a temporary file
Syntaxmktemp [ -c ] [ -d directory_name ] [ -p prefix ]
The command makes a name for the pathname of a temporary file and
writes that name to standard output. The name will not duplicate that
of an existing file. The command does not create a new file. The file
named must actually be created before can generate a new filename.
Subsequent calls to will only generate a new file name if all previ‐
ously generated file names have been created by the user and still
exist. Error messages are written to standard error.
The directory_name generated by is the concatenation of a directory
name, a slash (/), a file prefix, a dot (.), a four digit number and a
The directory name is chosen as follows:
(1) If the -d option is specified, directory_name is used.
(2) Otherwise, if the TMPDIR environment variable is set and a
string that would yield a unique name can be obtained using the
value of that variable as a directory name, this value is used.
(3) Otherwise, is used.
The prefix is chosen as follows:
(1) If the -p option is specified, prefix is used.
(2) Otherwise, if the LOGNAME environment variable is set, it is
used as the prefix.
(3) Otherwise, the user's login name is used.
Options-c Causes to attempt to create a regular file using the gener‐
ated (or created) name string. If file creation is success‐
ful, a zero length file is created with access permissions
derived from the process's file mode creation mask, see No
attempt is made to create a file if the length of the gen‐
erated (or created) name string exceeds 1023 characters. It
is the user's responsibility to remove files created by use
of this option.
Causes directory_name to be used as the directory portion
of the pathname. In this case, directory_name is used
instead of TMPDIR and
-p prefix Causes the string prefix to be used as the file's prefix.
It is used instead of LOGNAM and the user's login name. If
the prefix is longer the 249 characters, it will be
silently truncated to that length before the concatenation
of the suffix.
LOGNAME When the -p prefix option is not specified, the value of
this variable is used as the prefix of the filename, if it
TMPDIR When the -d directory_name option is not specified, the
value of this variable is used instead of
If the user does not have write permission in the directory specified,
and error message is reported and is used in its place. The entire path
name can not exceed 1023 characters, and the temporary file name can
not exceed 255 characters. If the generated file name is too long it is
truncated to fit before the suffix is added.