Introduction
You may find that /tmp becomes full regularly. This is usually the result of user's php scripts that aren't removing files they create in /tmp. There is a third-party program for clearing the /tmp directory called tmpwatch. This article will show you how to install tmpwatch and set up a cron job so that it can clean the /tmp directory of old files on a regular basis.
Procedure
-
Install tmpwatch if it's not installed. If you run this command when tmpwatch is already installed and on the latest version, it will tell you there is nothing to do and no harm will be caused.
yum install tmpwatch
-
Check how many files are in /tmp
ls -1 /tmp | wc -l
-
Run tmpwatch to clear the /tmp partition of files over a week old now. This command ignores symlinks and preserves certain systemd data stored in /tmp:
tmpwatch --verbose --mtime -l -X "/tmp/systemd-private*" 168 /tmp
-
Check to see if some files were actually removed from /tmp. If not, decrease the number of hours (in this case 168) until enough files are removed to give sufficient space in /tmp. Do not lower the number below 12.
ls -1 /tmp | wc -l
-
Add tmpwatch to root's crontab to clear old files (more than a week old) every night. If you lowered the number of hours in step 3, lower it here as well.
crontab -e
0 0 * * * tmpwatch --mtime -l -X "/tmp/systemd-private*" 168 /tmp
Additional Information
For more information on editing the crontab, see the following article:
How to edit the root crontab
Comments
0 comments
Article is closed for comments.