tags:

views:

80

answers:

4

I always heard that the proper way to find the temporary folder on a UNIX machine was to look at the TMP environment variable. When writing code that worked on Windows as well as Linux, I would check for TEMP and TMP.

Today, I discovered that my Ubuntu install does not have that environment variable at all.

I know it seems you can always count on /tmp being there to put your temporary files in, but I understood that TMP was the way the user could tell you to put the temporary files someplace else.

Is that still the case?

+3  A: 

POSIX/FHS says that /tmp is the root for temporary files, although some programs may choose to examine $TEMP or $TMP instead.

Ignacio Vazquez-Abrams
http://www.pathname.com/fhs/pub/fhs-2.3.html#TMPTEMPORARYFILES
Roger Pate
A: 

You can set the TMP or TEMP environment variable in /etc/environment and it will be available.

txwikinger
+1  A: 

A good way to create a temporary directory is using mktemp, e.g.

mktemp -d -t

This way, you can even make sure, that your file names won't collide with existing files.

Chris Lercher
A: 

You are probably thinking of TMPDIR.

This variable shall represent a pathname of a directory made available for programs that need a place to create temporary files.

Alok