Find best webhosting in chennai

Location

Chennai

Working Hours

09:00 AM to 07:00 PM ( Mon - Sat )

Phone Number

(+91) 9884800300

/tmp directory 100% full. How to fix.

This Article will explains about /tmp directory is 100% full how to fix it

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.

/tmp directory

Below is the few steps to check /tmp directory and fix the issue.

1. Check Current Usage

Run the following commands to analyze what’s consuming space:

df -h /tmp
du -sh /tmp/* | sort -h

This helps identify the largest files or directories in /tmp.

2. Remove Unnecessary Files

Since /tmp is a temporary storage location, it typically holds files that are safe to delete. Use:

rm -rf /tmp/*

Or, to be more cautious:

find /tmp -type f -atime +1 -exec rm {} \;

The -atime +1 flag removes files not accessed in the last day.

3. Stop Services Temporarily

If large temporary files are actively being created by services, stop the services to prevent further bloating:

systemctl stop <service_name>

4. Investigate Large Files

If some files are unexpectedly large, inspect them to understand their source:

ls -lh /tmp/
file <filename>
cat <filename> | head

This can help pinpoint if logs, temporary backups, or other data are causing the issue.

5. Check Applications Writing to /tmp

If the issue recurs, identify applications writing excessive data:

lsof +D /tmp

Address misconfigured applications, or redirect their temporary storage elsewhere.

6. Increase /tmp Space (Optional)

If /tmp is frequently running out of space:

  • Resize the partition (if /tmp is on its own partition):
lvextend -L +2G /dev/<volume_group>/<tmp_volume>
resize2fs /dev/<volume_group>/<tmp_volume>

Use tmpfs (RAM-backed storage): Edit /etc/fstab to increase size:

tmpfs /tmp tmpfs defaults,size=2G 0 0

Then remount: bash mount -o remount /tmp

7. Monitor Space Usage

To prevent future issues:

  • Implement a cleanup script in cron:
crontab -e

Add:

0 2 * * * find /tmp -type f -atime +1 -delete

Use monitoring tools like du, df, or ncdu for regular checks.

Further click here to know how to extract tar.gz files in Linux.