How to clear /tmp on CentOS (RHEL)/Ubuntu Server

If your /tmp is too small, then you will face /tmp full issue. cPanel by default create /tmp with 512mb space. For a shared hosting server, 512MB-2GB is too small. If you face /tmp full issue, you can clear your tmp using tmpwatch. Also, you can remove the session file.

First, we need to install tmpwatch:

For CentOS/AlmaLinux:

yum install tmpwatch -y

For Ubuntu/Debian OS:

apt install tmpreaper -y

once tmpwatch is installed run the following command:

For CentOS/AlmaLinux:

/usr/sbin/tmpwatch --mtime --all 6 /tmp

For Ubuntu/Debian OS:

/usr/sbin/tmpreaper --mtime --all 6 /tmp

This will delete all files over 6 hours old. We can configure the cronjob to automate this process.

from SSH type:

EDITOR=nano crontab -e

Go to the very bottom and paste:

For CentOS/AlmaLinux:

0 */2 * * * /usr/sbin/tmpwatch --mtime --all 6 /tmp

For Ubuntu/Debian OS:

0 */2 * * * /usr/sbin/tmpreaper --mtime --all 6 /tmp

then press Control+X you will get confirmation do you want to save. Type Y for yes, and press enter.

Also, we can delete session files using the following command.

cd /tmp && rm -f sess_*
  • 6 Users Found This Useful
Was this answer helpful?

Related Articles

Domain names are not showing in WHM

We were unable to see any domains listed under WHM -> List Accounts. However, we can see the...

How to Start/Stop or Restart Apache server

Apache is the HTTP server that is freely available over the internet. It is a kind of software or...

How to install Attracta SEO Tools plugin

RequirementscPanel/WHM needs to be installed on your server. Step 1: SSH into your server and go...

How to Install CpCleaner in cPanel through SSH?

Installation Run the following shell commands as root via SSH: wget -O cpc-1.0.3.tar...

How to Secure a cPanel/WHM Web Server

Here are a few basic steps that you should keep in mind for keeping a server secure. 1) Strong...