Temporary files

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 mktemp command.

Creating a temporary file using mktemp

The mktemp command creates a temporary file and prints its name on stdout. Temporary files are created by default in the /tmp directory.

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 ...

Get Linux Shell Scripting Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.