What is the tmp folder?
The /tmp is a directory containing 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, it will be saved anywhere, and the temporary files will be deleted as soon as you close the document.
What action will you take when the tmp directory is 100% full?
If the tmp folder is 100% full, we need to remove the files and folder from it to free up some space.
There are two things to remember when managing the Linux /tmp directory. First, you must know how to determine which files to remove from the /tmp directory. This is because randomly deleting files disrupts user activity. Next, you need a way to automate the process of cleaning up the /tmp directory. This is because it is impossible to find and regularly delete temporary files manually.
With these two points in mind, the best solution is to periodically use crontab to remove the files from the tmp directory.
If you want to remove the /tmp folder files manually, you need to stop all programs and services you are using 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.
# cd /tmp/ // To go to tmp directory
# pwd // To check the current working directory
# sudo rm -r * // To remove all files and folders present in the tmp
If you do not stop the application 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, then you need to restart the following command.
# systemctl restart apache2 // For Ubuntu OS
# systemctl restart httpd // For Centos OS
# systemctl restart mysqld
Causes:
Some programs stop working when the /tmp directory fills up. For example, you will not be able to upload files to websites because the /tmp folder will run out of space to store temporary files during uploads.