How can I get the temporary directory path in Ubuntu?
相关问题
- Why doesn't php sleep work in the windows-subs
- Installing Pydev for Eclipse throws error
- Error building gcc 4.8.3 from source: libstdc++.so
- what's the role of libopenssl-ruby?
- Docker why isn't $USER environment variable se
相关文章
- 为什么nfs在不同版本的Linux下安装的文件都不一样
- Incompatible JavaHl library loaded
- Python - Node.js (V8) runtime is not available on
- Converting PIL Image to GTK Pixbuf
- Ubuntu graphviz 'sfdp' not working
- Gearman , php extension problem : Class 'Gearm
- Decrease the tabs bar height in gnome terminal
- Can you get the parent GTK window from a widget?
On most Unix-like systems, you'd be looking for
/tmp
. If that's not quite the answer you were after, you should specify which bit of Ubuntu you're talking about.Certain applications will allow you to specify where their temporary files are put (such as with the
TMP
,TEMP
orTMPDIR
environment variables) but a lot of stuff would break under UNIX if/tmp
didn't exist, so it's safe just to use that. If you want to make it configurable, in your code, you'd use something like the functiongetTmpDir()
in the following complete program:which outputs, in my CygWin environment (I have both
TEMP
andTMP
set to this value):That's pretty much what the GLib
g_get_tmp_dir()
call does, though possibly in a different order.Of course, if you wanted to use an application-specific environment variable, you could put that before the others thus:
Or even take out some or all of the "standard" ones. But you should pretty much always fall back on
/tmp
if the user hasn't configured anything.From the command line:
Flocks,
Thanks for taking your time but what i am expecting is from the gnome link.
http://library.gnome.org/devel/glib/unstable/glib-Miscellaneous-Utility-Functions.html
using the API g_get_tmp_dir() we can have the location of temp directory
There is an environment variable TMPDIR which can set the location of the temporary dir, most programs respect this, if it's not set it will default to /tmp (or /var/tmp)
I looked at how Python does this, and there doesn't seem to be any specific UNIX interface to do so.
They just try, in sequence:
TMPDIR
,TEMP
, andTMP
/tmp
/var/tmp
/usr/tmp
Given that Python was written by people a lot smarter than I am, I'd be willing to bet this is probably the best you can do.