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

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

I wanted to know if there was a reccomended solution to storing temporary files.


If you are writing Applescript then do it the Applescript way. Applescript created a language construct for creating temporary files, so use it.

set temp to path to temporary items


The user of ~/Library/Caches/TemporaryItems/ means your temporary files will not interfere with other users, which is not the case for the standard Unix temporary directories. Then again, when Unix was created you measured disk sizes in megabytes (maybe even kilobytes). And since many systems had disk quotas, the shared temporary directoies allowed users places to create large scratch files in order to get a job done, but since the temporary directoies got deleted frequently it was not someplace they could store date long term. But today with gigabyte and terabyte storage available having a personal temporary directory is not as much of an issue.


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


Of course it makes sense. You are dealing with history, and trying to support different applications written across 40+ years, different programming languages, different scripting languages, etc... All of which were either written when the perferred temp location was different, so if you want the apps to run on your Unix, the system needs to support temp directories are different locations.


/tmp is original Unix temporary file location. But /tmp was on the boot drive, so eventually Unix implementations started to have /usr/tmp, as often /usr was on a different physical disk drive with more space. Eventually someone came up with /var and so Unix distributions started having a /var/tmp.


/private is a Mac OS X construct where Mac OS X stuff a lot of Unix standard directories that are private to the Mac OS X Unix implementation and the use of /private was intented to imply users should not mess with these files. So Mac OS X created a symbolic link that points to /private/tmp. /var is a symlink to /private/var, hence /var/tmp is really /private/var/tmp. You need to symlinks as traditional Unix apps will expect to find them via that path.


TMPDIR was a Unix environment variable created so that apps could find the preferred place to store temp files on the Unix platform they were running on, as not all places Unix was running had sufficient disk space for temp file in /tmp, or the user may want their app to store temp files somewhere else.


So if you are writing a Unix application that needs to run on any Unix system, then use mktemp or any of the family of Unix utilities and or functions that will make sure you are using the desired temp directory on your system, as well as making sure your temporary file name is unique and does not conflict with other users and applications.


But since you are using Applescript use the Applescript temporary file directory.

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

Most everything on OS X is duplicated several times, in different domains: user, computer, root (e.g. ~/Library, /Library, /System/Library). It shouldn't be surprizing that temp folders are duplicated as well. For your purpose any of them will do. If it makes you feel better I'll tell you that the recomended temp folder is path to temporary items, but it really doesn't make any difference.

Temporary Items

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