Easy Tutorial
❮ Linux Comm Setenv Linux Comm Ppp Off ❯

Linux mktemp Command

Linux Command Manual

The Linux mktemp command is used to create a temporary file.

mktemp creates a temporary file for use in shell scripts.

Syntax

mktemp [-qu][filename argument]

Parameters:

Example

When using the mktemp command to generate a temporary file, the filename argument should be provided in the format "filename.XXXX". mktemp will create a temporary file based on the filename argument. Enter the following command at the command prompt:

mktemp tmp.xxxx # Generate a temporary file

After using this command, you can use dir or ls to view the current directory, resulting in the following output:

cmd@cmd-desktop:~$ mktemp tmp.xxxx # Generate a temporary file  
cmd@cmd-desktop:~$ dir # View the current directory  
file test testfile testfile1 tmp.3847 # tmp.3847 has been generated

As shown, the generated temporary file is tmp.3847, where "XXXX" in the filename argument is replaced by 4 randomly generated characters.

Linux Command Manual

❮ Linux Comm Setenv Linux Comm Ppp Off ❯