On a cPanel VPS, if /tmp directory is 100% full. What actions are required, and does it cause any problems?

In this article we will learn about /tmp directory and issues when /tmp directory is 100% and how to rectify them.

What is the tmp directory?

The tmp is a directory that contains necessary files temporarily needed by the system and other software and applications running on the server. For example, when you create a document, the entire contents of that document are saved as temporary files in the /tmp directory. When you save a file, it can be saved anywhere, and the temporary file will get deleted as soon as you close the document.

What actions are needed when the /tmp directory is 100% full?

When the tmp folder is 100% full, we need to remove the files and folder from the /tmp folder to free up some space.
There are two things to remember when managing the Linux /tmp directory.

  • Firstly, you must know how to determine which files can be removed from the /tmp directory because randomly deleting files can disrupt user activity.
  • Secondly, you need a way to make an automated process of cleaning up the /tmp directory. Because it is impossible to find and manually delete temporary files at regular intervals. With these two points in mind, the best solution is to periodically use crontab to remove the files from the tmp directory.

Steps to open CLI(Command Line Interface)

  1. Login into WHM as root user
  2. Under the Server Configuration section, click on Terminal..
    WHM Terminal

Assuming that you want to remove the /tmp folder files manually, you need to stop all programs and services being used, before removing the files. This is because the programs use /tmp/to store information for the session temporarily. The names of files in the /tmp/directory mainly indicate which program the file belongs to.

  • To go to the tmp directory
    # cd /tmp/
  • To check the current working directory
    # pwd
  • To remove all files and folders present in the tmp directory
    # sudo rm -r *

If you do not stop the applications and delete the files from the /tmp folder, then the file will be deleted, and you will not see it anymore, but it will still have space assigned to it. Generally, these files are used by Apache and MySQL. You can use the below-mentioned command to check the application.

# lsof | grep /tmp

To clean the space, check the command output and restart the services accordingly. For example, if the files are from Apache and MySQL, you need to restart the services using the following commands.

Commands to restart apache and mysql service

  • For Ubuntu OS
    # systemctl restart apache2
  • For Centos OS
    # systemctl restart httpd
  • For mysql service
    # systemctl restart mysqld

Causes:

Some programs stop working when the /tmp directory fills up. For example, you may not be able to upload files to websites, because the /tmp folder will run out of space to store temporary files during uploads.

Add a Comment

Your email address will not be published. Required fields are marked *