Temporary files are the files that are needed for a short interval of time while an application is running. Such files are being used to keep intermediate results of running a program and they are no longer needed after the program execution is complete. In shell, we can create temporary files using the
The syntax of creating a temporary file is as follows:
$ mktmp /tmp/tmp.xEXXxYeRcF
A file with the name
tmp.xEXXxYeRcF gets created into the
/tmp directory. We can further read and write into this file in an application for temporary use. Using the
mktemp command instead of using a random name for a temporary filename avoids accidental overwrite of an existing temporary file.
To create a temporary directory, we can use the
-d option with
$ temp_dir=mktemp -d $ echo $temp_dir /tmp...