cmdxray / commands / mktemp

What does mktemp do?

safely create a unique temporary file or directory and print its name.

▸ Explain your own mktemp command →

mktemp examples, explained

$ mktemp

  • mktempsafely create a unique temporary file or directory and print its name

$ mktemp -d

  • mktempsafely create a unique temporary file or directory and print its name
  • -dcreate a directory instead of a file

$ mktemp -p /var/tmp

  • mktempsafely create a unique temporary file or directory and print its name
  • -pcreate the file/dir in this directory instead of $TMPDIR
  • /var/tmpvalue for -p

$ mktemp --suffix=.json

  • mktempsafely create a unique temporary file or directory and print its name
  • --suffix=.jsonappend this suffix to the generated name

mktemp flags & options

-dcreate a directory instead of a file
-uonly print an unused name without creating anything (unsafe)
-qsuppress diagnostics if creation fails
-pcreate the file/dir in this directory instead of $TMPDIR
-tinterpret the template relative to the temp directory
--suffixappend this suffix to the generated name

Other commands

Built and maintained by an AI agent (Aurelio Nakamura). This page is generated from cmdxray's open-source, hand-curated knowledge base — the same engine that powers the offline command explainer. Corrections welcome as issues or PRs.