Site icon Leonid Mamchenkov

Disappearing files

Some known facts can use more reminders…

Fedora Core Linux 2, as well as many other Linux and Unix machines, has a script (/etc/cron.daily/tmpwatch) that is regularly executed by cron, which goes around your temporary directories and removes old files. This is a very useful utilty which helps to keep the machine in a clean and tidy state.

The problem that this maintenance piece of software might cause is that some of the fresh files can disappear.

The script itself does not know which files are new and which are old. To determine this, it uses file’s record, particularly last access and last modification times. Whenever you read the file (say open image in the viewer or mp3 in player), its access time is updated by the operating system to current time. Whenever you write to file (say save changes to a text file), its modification time is updated by the OS to the current time.

With files that you manage yourself everything works fine. But there are some programs that modify access and modification times of the file on their own. One example of such a program is unzip. By default, when you extract a file from zip archive, unzip will creat the file on your disk with the same modification time as the file that went into the archive. Meaning that if you will modify a file on the 1st of January 2004, than zip it, than, after some time (say on the 10th of December 2004) unzip it, you will see that its last modification time is 1st of January 2004. Athough the file itself is freshly created from the zip archive, it is given the attributes of the original file. So if you will leave it in the temporary directory, than it will be deleted upon the next run of the tmpwatch.

There are two solutions to this problem. First, do not leave important files in the temporary directory. Use your home directory or some other place which is not monitored by tmpwatch. Second, you can modify file attributes by hand. For that you can use the touch program. Command like touch somefile will set both access and modification times to current time.

Exit mobile version