UNIX Hints & Hacks

ContentsIndex

Chapter 6: File Management

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

6.1 Copy Files with Permissions and Time Stamps

 

6.5 Finding Files with grep

 

6.8 Moving and Renaming Groups of Files

 

6.11 Splitting Files

6.2 Copy Files Remotely

 

6.6 Multiple grep

 

6.9 Stripping the Man Pages

 

6.12 Limit the Size of the Core

6.3 Which tmp Is a Good Temp?

 

6.7 Executing Commands Recursively with find

 

6.10 Clean Up DOS Files

 

6.13 uuencode and uudecode

6.4 Dealing with Symbolic Links

 

 

 

 

 

 

 

6.3 Which tmp Is a Good Temp?

6.3.1 Description

6.3.1 Description

Knowing where to put temporary files can be key to saving or losing the files. There are four types of temporary areas that should be used when managing files and the system.

Example One: Files in /tmp

Flavors: AT&T, BSD

When a file is put in /tmp it can be expected that it will be removed either at a scheduled time or the next time the system reboots. This area is designated for what it truly is, a place for temporary files. The system checks and uses the /tmp area for its own use as well. Some flavors, such as Solaris, actually have /tmp be the swap partition. As you know, nothing ever lasts very long in swap. Do not store anything long-term or even something that you might need in a couple of hours. It might not be there when you return.

Many times system administrators put patches, restored data, log files, and other useful files into /tmp. This is considered taking an unnecessary risk. So what does get stored in /tmp?

This area is extremely useful for creating data files for testing, lock files, and other files that you expect to be removed if forgotten about. Do not put any vital data or programs into /tmp. On some flavors, at the time of booting the system, a recursive deletion of files doesn't take place. You can create subdirectories with files in them and not worry about the files being removed. Check with your flavor of UNIX--if /tmp makes up the swap partition on your system, you will not be able to get away with this hack.

Large temporary files should not be kept in this area. The /tmp directory often resides in the root partition. If the root partition fills up, this can lead to the system crashing or grinding to a halt. If you have the disk space you should leave it on the root system.

If the /tmp area is inaccessible, the system does not boot up into a multiuser state. Avoid doing certain things with /tmp to save yourself a lot of grief in the long run:

Example Two: Files in /usr/tmp -> /var/tmp

Flavors: AT&T, BSD

In many cases you will see that /usr/tmp is a symbolic link to /var/tmp. Files that are kept in /usr typically are not supposed to fluctuate in size. Those areas in /usr that do change in size are often linked to /var or some other area with more disk space than /usr. These directories include mail, local, spool, and even tmp.

The size of this temporary area is often larger then the /tmp area. It is an area that is good for storing application-related temporary files, patches waiting to be installed, and administrative temporary files, such as log files, build reports, or anything that doesn't need permanent storage. Files here have to be removed manually from a scheduled job that is set up from the crontab.

If /var/tmp lacks sufficient disk space to handle the temporary area and the disk fills up, the only things that would break are any services in /var. These could include mail, printing, scheduling, and accounting. Although it is not recommended or good administrative practice, if there is more disk space in /usr then in /var, you can reverse the direction of the symbolic link.

Where:

rocket 25% ls -l /usr/tmp
lrwxrwxrwx   1 root     sys        8 Nov 21 00:07 tmp -> /var/tmp

Becomes:

rocket 26% ls -l /var/tmp
lrwxrwxrwx   1 root     sys        8 Nov 21 00:07 tmp -> /usr/tmp

Warning - There are repercussions for making a change in this structure. The system might begin to grind to a halt if the disk space on the /usr partition reaches 100% capacity. There is also a chance of the system crashing when it fills up.


Most users and developers do one of two things. They are unaware that this area exists and come close to filling up /tmp. Then there is the other end of the spectrum: They exploit the area to the fullest and you have to sometimes fight to get the area cleaned up.

Example Three: Extra Filesystems with tmp

Flavors: AT&T, BSD

Now that there is an increase of available disk capacity on a single disk, multiple disks and raid arrays are becoming more prevalent than ever before. It is a good idea to create at least one temporary area on any one of the un-system-related filesystems. If you have multiple volumes or filesystems like /vol01, /vol02, and /vol03, select one that might not fill up as fast as the others and make a temporary directory within it (that is, /vol02/tmp).

This new area can be designated just for the users. This temporary area is perfect for the users to use or throw whatever files, extraneous code, and data that they want to temporarily work with. Make it known to the users that this area is set up just for them. They need to be informed that they can work in this area and stay out of /tmp or /usr/tmp, they will not be affecting the system disks in any way, and they might also show an increase in performance if they stay in the designated temporary area you set up for them. Users always like to hear about anything that might show an increase in performance to their system.

In many cases you don't know what the user is up to or what programs they are running or trying to run. Unlike /tmp and /usr/tmp, which can have files removed on a regular basis, the removal of data here can be handled in two ways. If the disk utilization meets a certain threshold, like 95%, files older that 3-7 days can be removed. You can also set up the crontab to remove data older than n days on a weekly basis. Check with the main user or project leader of the system to find out which method they would prefer.

If this area can be viewed by many workstations over NFS mount points, you might want to put files that are of interest to many users in this area. Many times large files on the Internet can be of interest to users. These sometimes can be files or programs that more than one user will want to see but not keep. Sometimes many users want to view large and popular QuickTime movie files. It is best to take a proactive approach and place these files into the temporary area so that you don't have so many copies of a large redundant file sitting all around your system. You can do the math of a 30MB file with 100 users each wanting a copy. Think of all the wasted tape you will be using for backups and disk space. Check with management first.

In many cases, downloading these types of files is prohibited by company policy. Management has been known to be lenient depending on the environment and the content of the material. Typically it is nonpornographic material and isn't in poor taste. It can also be justified by explaining the amount of disk space, tapes, and time that potentially could be wasted by their employees. If any disks have filled up in the past due to a similar instance, you should notify management that this could be a way of preventing this sort of thing from happening again.

Example Four: User's Temporary Directory

Flavors: AT&T, BSD

Setting up a temporary area in a user's home directory works very well to keep the user out of the system's temporary directories. Users can place any downloaded files or data they are temporarily working with in this area. Eventually disk space fills up; when it does and the call goes out to clean up files, users can go straight to their temporary area and clean up these files first.

This is sometimes a cleaner alternative to one large temporary area on an extra filesystem for many to share. If a large number of people are accessing the one shared area, some begin to look elsewhere for other places to start dumping files.

Reason

There is never a user who keeps things forever; everyone needs a place to occasionally dump their junk files. A directory for temporary storage is necessary for the user and its location can be vital to the integrity of the system.

Real World Experience

Users often need to be told where to put files, and you need to be the one to tell them. If you configure the system, you should know what's best. When users do not have any place to store things temporarily, they have a tendency to begin creating frivolous and meaningless directories throughout the system. Administering and cleaning up these directories and files become a nightmare.

Backups should never be done on any temporary directories or files unless specifically requested by a user. If it is requested, try to make it clear that these backups will take place for only n days and then will cease to exist. In a year's time, performing backups on these areas could run to gigabytes of worthless space and data.

When you are working with temporary directories, keep in mind some of the basic rules that should be covered.

UNIX Hints & Hacks

ContentsIndex

Chapter 6: File Management

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

6.1 Copy Files with Permissions and Time Stamps

 

6.5 Finding Files with grep

 

6.8 Moving and Renaming Groups of Files

 

6.11 Splitting Files

6.2 Copy Files Remotely

 

6.6 Multiple grep

 

6.9 Stripping the Man Pages

 

6.12 Limit the Size of the Core

6.3 Which tmp Is a Good Temp?

 

6.7 Executing Commands Recursively with find

 

6.10 Clean Up DOS Files

 

6.13 uuencode and uudecode

6.4 Dealing with Symbolic Links

 

 

 

 

 

 

 

© Copyright Macmillan USA. All rights reserved.