Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find the 'temp' directory in Linux?

Tags:

c++

linux

How do I find the 'temp' directory in Linux? I am writing a platform neutral C++ function that returns the temp directory. In Mac and Windows, there is an API that returns these results. In Linux, I'm stumped. ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­

like image 247
Charles K Avatar asked Aug 27 '08 19:08

Charles K


People also ask

Where is the Temp directory located?

Most programs will create temp files in a folder called C:\Users\AppData\Local\Temp — that's likely where your computer stores the majority of your temporary files.

What is tmp directory Linux?

The /tmp directory is a temporary landing place for files. Users also have write access to this directory, which can be a bad thing, but there is a solution.


1 Answers

Check following variables:

  • The environment variable TMPDIR
  • The value of the P_tmpdir macro

If all fails try to use the directory /tmp.

You can also use tempnam function to generate a unique temporary file name.

like image 181
Greg Dan Avatar answered Oct 12 '22 23:10

Greg Dan