You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Temporary Items

Is there an article detailing the difference between the locations below?


What is the reccomended usage? How often are the items deleted? What causes them to be deleted?


path to temporary items
path to temporary items from user domain
/private/var/folders
/tmp
/private/tmp
/var/private/tmp

Mac OS X (10.7.5)

Posted on Apr 27, 2013 8:10 AM

Reply
Question marked as Top-ranking reply

Posted on Apr 27, 2013 8:49 AM

/tmp and /private/tmp are the same folder (/tmp is a soft link to /private/tmp). It's the same for /var and /private/var.


There is no such thing as /var/private/tmp (I assume that was a typo).


/tmp and /var/tmp are used as temporary scratchpad space by various applications. Based on the BSD Unix directory structure (which OS X mostly follows), /tmp is used for temporary files that should not survive a reboot and /var/tmp for temporary files that should survive a reboot (although this is a bit flexible). They often contain things like launchd sockets.


/var/folders is often used for temporary downloads (eg, appliactions that update by downloading new versions of themselves often download the dmg files to a subdirectory of /var/foldersand extract them there before running their own installer).


"path to..." comes from the intersection between the OS X user domains management system and the fielsystem; it is highly context dependent and arcane.

20 replies
Question marked as Top-ranking reply

Apr 27, 2013 8:49 AM in response to adayzdone

/tmp and /private/tmp are the same folder (/tmp is a soft link to /private/tmp). It's the same for /var and /private/var.


There is no such thing as /var/private/tmp (I assume that was a typo).


/tmp and /var/tmp are used as temporary scratchpad space by various applications. Based on the BSD Unix directory structure (which OS X mostly follows), /tmp is used for temporary files that should not survive a reboot and /var/tmp for temporary files that should survive a reboot (although this is a bit flexible). They often contain things like launchd sockets.


/var/folders is often used for temporary downloads (eg, appliactions that update by downloading new versions of themselves often download the dmg files to a subdirectory of /var/foldersand extract them there before running their own installer).


"path to..." comes from the intersection between the OS X user domains management system and the fielsystem; it is highly context dependent and arcane.

Apr 27, 2013 8:59 AM in response to g_wolfman

g_wolfman wrote:


"path to..." comes from the intersection between the OS X user domains management system and the fielsystem; it is highly context dependent and arcane.

If I was writing an AppleScript app that needed to store items until the app terminated, or until the next reboot, where would I store these files? In /tmp or path to temporary items from user domain?


Is there a doc in the development docs that has an in-depth description of each?


Thanks for the time.

Apr 27, 2013 10:29 AM in response to adayzdone

adayzdone wrote:


If I was writing an AppleScript app that needed to store items until the app terminated, or until the next reboot, where would I store these files?


Temporary item folders are nothing more than scratch folders which are emptied by the system at arbitrary points in time. I believe one of the periodic scripts (com.apple.periodic-daily, com.apple.periodic-weekly, com.apple.periodic-monthly) takes care of it. The point is, you can rely on files in a temporary folder to remain there as long as your app is using them, but once you let them go they may or may not be there the next time you look.


if you need a file to be available until the next reboot, don't use a temp folder. Store it somewhere and have your app delete it when it's done. If you only need a file for the the current run of your application, then any of them will work fine. I usually use path to temporary items, myself.

Apr 27, 2013 1:59 PM in response to adayzdone

The only significant difference would be access. the '...from user domain' one resolves to:


'~/Library/Caches/TemporaryItems/'


which anyone who has general user priviliges can find and access. The other resolves to something like:

'/private/var/folders/##/<randomstring>/#/TemporaryItems/'


which is out of a general user's scope. I mean, they could access it if they could find it, but they can't search the folder heirarchy and probably can't guess the random string, so they're effectively SOL.

Apr 27, 2013 2:18 PM in response to adayzdone

As I said earlier, persistence is arbitrary. If you do anything that relies on the persistence of an item in a temp folder, sooner or later it's going to bomb out on you.


If you're really curious, you can look through the files and subfolder of /etc/periodic, which contains all of the periodic scripts (don't be thrown off by the unix executable icons, those files are just bash scripts). That may or may not be sufficient - I just noticed the temp folder I made for the above example has disappeared, and it's doubtful (but possible) that one of the periodic scripts kicked off in the last couple of hours.


But really, the only safe approach is to consider temp files to be deleted immediately after you finish using them. Anything else is just asking for trouble.

Apr 27, 2013 4:23 PM in response to adayzdone

Honestly, I think you're way over-thinking this. There's nothing special about a temp folder except that the system clears it out periodically. If you're concerned about persistence, create your own temp folder; it's easy. Make a folder somewhere, then create a launchd item that deletes its contents according to your schedule.


Really, I'm trying to imagine a context in which using one temp folder or another would make a difference, and I'm having a hard time visualizing it. can you give a concrete example of what you're trying to do that shows what you're worried about?

Apr 27, 2013 4:37 PM in response to twtwtw

With most topics, everyone seems to be on the same page ... except this one. From irc another user states: "but whatever you do, do *not* use /private/tmp"


set temp to path to temporary items
set tempUser to path to temporary items from user domain
set tempShell to do shell script "echo $TMPDIR"
/private/tmp


All refer to different locations. Although I plan on having the app clear the data anyway, I wanted to know if there was a reccomended solution to storing temporary files. It doesn't make sense that there would be four locations which are meant to function identically.


I plan on downloading images to be displayed as icons in an Alfred workflow. After the workflow terminates, delete them. In case the error handler doesn't catch them correctly, delete the directory upon reset.

Apr 27, 2013 5:18 PM in response to adayzdone

As twtwtw states you're over thinking this.


/tmp (which links to /private/tmp) is the standard *nix place to put files that you don;t care about past the current run of the program.


It will be cleaned out at boot and files that are in it that have not been accessed over a certain amount of time (a few days in OS X I believe) will be deleted by the daily periodic script. This ensures that systems that are not rebooted often will not choke on /tmp.

It doesn't make sense that there would be four locations which are meant to function identically.

True but remember OS X is an amalgamation of different OS's and different OS philosophies. What you are seeing when you look at the different temp folders is that amalgamation. OS X was built with a bit of *nix andNext and even some OS 9. You have to keep this in mind when you look 'under the hood' you'll find this same duplication in other areas of the OS also.

Temporary Items

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.