home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 21.1 A Grab-Bag Chapter 21
More About Managing Files
Next: 21.3 Unique Names for Temporary 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

Previous: 21.1 A Grab-Bag UNIX Power Tools Next: 21.3 Unique Names for Temporary Files
21.1 A Grab-Bag Book Index 21.3 Unique Names for Temporary Files

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System