[Chapter 21] 21.2 A Better Place for Temporary Files: /tmp
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:39:59Z

#

| Chapter 21 More About Managing Files |

## 21.2 A Better Place for Temporary Files: /tmp

How many times have you made a little test file for something:

>     % grep foo bar > baz

then forgotten to remove baz-and found it, weeks later, cluttering up your directory and wasting disk space? Yeah, me too. So I decided to make my temporary files in the system temporary-file directory, /tmp.

Everyone on the system has permission to write files there. Because there are lots of temporary files, it's good to use a name that won't conflict with other people's files (21.3).

If your file doesn't have world permission (22.4, 22.2), other people on the system won't be able to read or write it. But they may be able to rename or remove it (23.10) unless the /tmp directory's sticky bit (22.6) is set. That usually isn't a problem, but you should know that it can happen.

Most systems delete leftover files in /tmp every day or so, when the filesystem fills up, or at least when the system is rebooted. So, don't use /tmp for a file that you want to keep for a while. Your system may have other directories for temporary files, like /usr/tmp (21.4), that aren't erased as often. Your system administrator should be able to tell you.

- JP

21.1 A Grab-Bag |  | 21.3 Unique Names for Temporary Files