Cleaning the /tmp partition

If you have a server running Centos or most other flavours of Linux or you use cPanel/WHM for your box, you will often find that the /tmp partition slowly gets full over time and will eventually get clogged up. The net result of this is a reduction in the performance of your sites and in some cases, the server will grind to a halt.

It is good practice then to keep on top of this usage on a regular basis. Now before you dive in and just bin everything in the /tmp partition, be careful as often the mysql.sock file is in there if you run MySQL on the box and deleting that can cause you some fun.

The command below will safely clean your /tmp partition:

find /tmp -type f -mtime +5 -exec rm -f {} \;

Now just to break this down, the command is basically looking at the /tmp partition for files that are older than 5 days. The rm -f section means to force the removal of the file/directory (in this instance the file).

Stick the above command in a cron and run it say once a week and your /tmp partition should behave itself.

Leave a Reply