Linux mktemp command
The Linux mktemp command is used to create temporary files.
mktemp creates a temporary file for use by shell scripts.
Syntax
mktemp [-qu][文件名参数]
Parameters:
- -q: If an error occurs during execution, no information is displayed.
- -u: The temporary file will be deleted before mktemp finishes.
- [filename parameter]: The filename parameter must be in the format "custom_name.XXXXXX".
Examples
When using the mktemp command to generate a temporary file, the filename parameter should be given in the format "filename.XXXX". mktemp will create a temporary file based on the filename parameter. Enter the following command at the command prompt:
mktemp tmp.xxxx #生成临时文件
After using this command, you can use dir or ls to view the current directory, and get the following result:
cmd@cmd-desktop:~$ mktemp tmp.xxxx #生成临时文件 cmd@cmd-desktop:~$dir #查看当前目录 file test testfile testfile1 tmp.3847 #生成了tmp.3847
It can be seen that the generated temporary file is tmp.3847, where the "XXXX" in the filename parameter is replaced by 4 randomly generated characters.
Other Extensions
Linux Command Reference