commands
mktemp — create a temporary file or directory
GNU mktemp securely creates a unique file or directory from a template and prints the path; test success before use. Do not use dry-run names for real files. Example assumes a fresh shell lab fixture with new output names.
Formal Syntax & Structure
linux syntaxlinux
mktemp [-d] [TEMPLATE]Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| -d | option | create directory |
| TEMPLATE | operand | Optional template containing at least three consecutive X characters in the last path component. GNU default uses TMPDIR or /tmp. |
Return Value
exit status and output
GNU mktemp securely creates a unique file or directory from a template and prints the path; test success before use. Do not use dry-run names for real files.
Working Example
Example Snippetlinux
p=$(mktemp -d ./scratch.XXXXXXXX) || exit 1stat -c '%a' "$p"rmdir -- "$p"