Forrest logo
back to the mktemp tool

mktemp:tldr:50f7d

mktemp: Create an empty temporary file and print the absolute path to it.
$ mktemp
try on your machine

The command "mktemp" is a Unix command used to create temporary files and directories with unique names. It stands for "make temporary".

When executed, the mktemp command creates a temporary file or directory in a secure manner, ensuring that the name generated is unique and cannot be predicted by other users or processes. This is particularly useful when writing shell scripts or running commands that require temporary storage.

The typical syntax for mktemp is:

mktemp [options] [template]

The "template" argument is an optional parameter that specifies a string with a combination of letters, numbers, and special characters. The template is used as a base to generate the temporary file or directory name, and the "X" in the template is replaced with randomly generated alphanumeric characters.

Some common options for mktemp include:

  • -d: Creates a temporary directory instead of a file.
  • -u: Just returns the generated name without creating any file or directory.
  • -p : Specifies a specific directory in which to create the temporary file or directory.

Here are a few examples:

  1. Creating a temporary file: $ mktemp Output: /tmp/tmp.ABC123

  2. Creating a temporary directory: $ mktemp -d Output: /tmp/tmpdir.XYZ789

  3. Creating a temporary file with a custom template: $ mktemp mytempfile_XXXXX.txt Output: mytempfile_jhGF6.txt

Overall, the mktemp command is a handy tool for generating unique temporary names and locations, ensuring secure and predictable temporary storage in Unix-based systems.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the mktemp tool