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. Now we’re gonna teach you to use the mktemp command in Linux.
The syntax of the mktemp command
$ mktemp [option] … [template]
You have just created a temporary file in the tmp directory. And the filename is also generated automatically.
Creating a temporary directory
To do this. Let’s add the option -d into the command:
$ mktemp -d
Name the temporary file
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
Adding the suffix
To do this. Let’s add the option –suffix into the command. For example:
$ mktemp newfileXXX --suffix ".txt"
We just taught you to use the mktemp command in Linux.
Thank you for referring!