Temporary files are used to temporarily store data that the operating system needs temporarily during operation and will disappear when no longer needed. they will disappear on their own after reboot.
This command in Linux allows the user to make a temporary file or directory in the tmp folder.
Here at Ibmi Media, we shall look into how to use the mktemp command in Linux.
It's syntax is given below:
$ mktemp [option] … [template]
For example, if you run the below command:
$ mktemp
The output will show that a temporary file has been created in the tmp directory with a filename generated automatically.
Using the mktemp command with the option -d as shown below:
$ mktemp -d
You will be able to create a temporary directory.
If you want to name the temporary file, add more than 3 X's at the end. For example:
$ mktemp newfileXXX
Or you can name the temporary directory:
$ mktemp -d newdicXXX
You can use the option –suffix with the mktemp command to add a suffix as shown below:
$ mktemp newfileXXX --suffix ".txt"
This article covers how to use the mktemp command in Linux. In fact, mktemp can help to Create temporary files or directoriesin your Linux system.