community man page

mktemp

Create a temporary file or directory.

12 examples·source: tldr · CC-BY·status: verified
Reading is open to everyone. Suggesting a flag, fixing an example or adding a recipe is opening to verified-email accounts soon — every change is moderated before it goes live.
curl https://curlhub.sh/man/mktemp
same page, in your terminal

Examples

Create an empty temporary file and print its absolute path GNU

mktemp

Use a custom directory (defaults to `$TMPDIR`, or `/tmp`) GNU

mktemp [-p |--tmpdir=]/path/to/temporary_directory

Use a custom path template (`X`s are replaced with random alphanumeric characters) GNU

mktemp /tmp/example.XXXXXXXX

Use a custom file name template GNU

mktemp -t example.XXXXXXXX

Create an empty temporary file with the given suffix and print its absolute path GNU

mktemp --suffix .ext

Create an empty temporary directory and print its absolute path GNU

mktemp [-d|--directory]

Print the name of a temporary file or directory without actually creating it GNU

mktemp [-u|--dry-run]

Create an empty temporary file and print its absolute path

mktemp

Use a custom directory if `$TMPDIR` is not set (the default is platform-dependent, but usually `/tmp`)

mktemp -p /path/to/temporary_directory

Use a custom path template (`X`s are replaced with random alphanumeric characters)

mktemp /tmp/example.XXXXXXXX

Use a custom file name template

mktemp -t example.XXXXXXXX

Create an empty temporary directory and print its absolute path

mktemp -d