Sometime your /tmp directly will be full and this can cause serious issues on server with WHM / CPanel. You can however run tmpwatch to clean /tmp directory and can setup a cron job for it to be run automatically each day.
/tmp becomes full regularly normally due to the user’s php scripts that aren’t removing files they create in /tmp. The third party program called tmpwatch is good in such kind of situation on Linux. We tested it on CentOs 7 as of date and it worked fine.
Setup tmpwatch
1. 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
2. Check how many files are in /tmp
ls -1 /tmp | wc -l
3. Run tmpwatch to clear the /tmp partition of files over a week old now (24 hours x 7 days = 168):
tmpwatch --mtime --all 168 /tmp
4. 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
5. Add tmpwatch to root’s crontab to clear old files (more than a week old) every night. If you needed to lower the number of hours in step 3, lower it here as well. For more information on editing the crontab, see How to edit the root user’s crontab
crontab -e
0 0 * * * tmpwatch --mtime --all 168 /tmp
