Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Does Linux have a standard temporary directory for general use, like Windows's C:\Temp folder? If so, where is it located? I found an SO question about finding a tmp directory programmatically, but I want to set a temp location in an XML config file ahead of time.

share|improve this question
1  
I know this looks like a really easy question, but I couldn't find a clear, simple answer through searching. Many of the results I got were for program-specific temp directories/files. I did see multiple references to /tmp, but they were ambiguous about whether that's standard for Linux or just a common convention. –  Pops Sep 6 '11 at 19:45
    
Windows's C:\Temp is most certainly not standard. Windows 95 already had %TEMP% pointing to C:\WINDOWS\Temp. –  grawity Sep 6 '11 at 21:31

3 Answers 3

up vote 16 down vote accepted

The Filesystem Hierarchy Standard says:

The /tmp directory must be made available for programs that require temporary files.

Programs must not assume that any files or directories in /tmp are preserved between invocations of the program.

and

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. Although data stored in /var/tmp is typically deleted in a site-specific manner, it is recommended that deletions occur at a less frequent interval than /tmp.

share|improve this answer
1  
+1 for faster fingers –  OldWolf Sep 6 '11 at 20:13
    
It's hard to argue with the standard. Thanks! –  Pops Sep 6 '11 at 20:46

Yes /tmp is for general use. See here and here On the Filesystem Hierarchy Standard.

/tmp/ Temporary files (see also /var/tmp). Often not preserved between system reboots.

With some more details listed in the PDF.

share|improve this answer

You cannot choose a single temporary directory name ahead of time that will work for any Linux system. In fact, you can't do that on Windows either. According to Wikipedia's article on temporary folders, the temporary directory on Windows is determined by the environment variable TEMP. If you were simply using c:\Temp as a temporary directory on a Windows system that set TEMP to something else, then any program using your XML file to choose a temporary directory would fail.

In short, the system temporary directory is determined by the environment on all modern operating systems that I know of, including both Windows and any UNIX-like system. Setting a single static path as your temporary directory will only work as long as the defaults have not been changed.

Anyway, the standard temporary directory in a typical Linux system is /tmp. It is the equivalent of C:\Temp in the sense that it is only the default temporary directory, not universal. Even if /tmp is available, if a user (or the system) has set the TEMP environment variable, the value of that variable should be used instead.

You could try choosing a temporary directory relative to the user's home directory, which you can create.

share|improve this answer
    
In my case, I think it's a safe assumption that the defaults are still in place, but this is definitely good to keep in mind. –  Pops Sep 6 '11 at 20:47
    
Some programs like bash, gcc, inkscape or lynx use the TMPDIR environment variable. –  Cristian Ciupitu Sep 7 '11 at 0:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.