Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the benefits of using the 'official' temp directory for the OS?

Tags:

node.js

I've noticed packages like node-temp and node-tmp, which provide APIs for writing temporary files to the appropriate temp directory for the current OS, e.g. /tmp.

What are the benefits of doing this, compared with simply storing temporary files in a subdirectory of your module/application (e.g. ./temp)?

like image 857
callum Avatar asked Jul 30 '13 11:07

callum


People also ask

What is the Temp directory used for?

The Temp folder is a directory on your Windows PC used to store temporary files. Clearing the Temp folder is a standard procedure for system administration to reduce the amount of storage space used.

What is a temporary directory on a computer?

In computing, a temporary folder or temporary directory is a directory used to hold temporary files. Many operating systems and some software automatically delete the contents of this directory at bootup or at regular intervals, leaving the directory itself intact.

What is special about the tmp directory when compared to other directories?

The /var/tmp directory is made available for programs that require temporary files or directories that are preserved between system reboots. Therefore, data stored in /var/tmp is more persistent than data in /tmp . Files and directories located in /var/tmp must not be deleted when the system is booted.

What is temporary directory Python?

Practical Data Science using PythonThe tempfile module in standard library defines functions for creating temporary files and directories. They are created in special temp directories that are defined by operating system file systems.


1 Answers

It is certainly operating system specific.

On most Linux systems /tmp is a tmpfs file system, which works much faster (because all data stays nearly in RAM) than a conventional disk file system.

Also, the official /tmp/ file system is often a setuid directory. This impacts on who has the permission to delete files inside it.

And some systems are administrated specially and might have periodic cron jobs to clean that /tmp. Also, system administrators know about /tmp/ (and might avoid making backups of it, put it on a fast disk, if not on tmpfs etc...) .... And the Linux Standard Base requires it...

You could use also the TMPDIR environment variable.

like image 129
Basile Starynkevitch Avatar answered Sep 17 '22 22:09

Basile Starynkevitch