How to Delete Failed PHP Files Upload in Linux Tmp Directory

May 31, 2020 | By Gerald | Filed in: Fixes.
Delete Failed PHP file on tmp Linux folder

In this tutorial, you will learn how to delete a failed PHP files upload in a tmp Linux directory. The files are unpredictable that can consume a lot of disk space on the volume.

If you encounter similar to php files below saved on your linux tmp directory that will consume your disk space, you really need to keep track of these files so that your server will not hang up in case you will encounter not enough space on volumes. If ever you are using an Amazon EC2, you can easily to setup a metrics monitoring and alerts for your EBS volumes.

Check out this guide>> to create a resource monitoring for your EC2 instance volume.

However, you’re trying to delete temporary PHP files, but the disk volume still does not decrease, or no changes made?

Similar to this:

Filesystem      Size  Used Avail Use% Mounted on
udev            468M     0  468M   0% /dev
tmpfs            98M  804K   98M   1% /run
/dev/xvda1      7.7G  7.7G     0 100% /
tmpfs           490M     0  490M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           490M     0  490M   0% /sys/fs/cgroup
/dev/loop0       94M   94M     0 100% /snap/core/8935
/dev/loop1       94M   94M     0 100% /snap/core/9066
tmpfs            98M     0   98M   0% /run/user/1000

Quick Solution

Therefore, I created a temporary solution using a Bash script to automatically clean up the failed PHP files to save disk space on your root directory volume. The script determines for deleted PHP files to kill those files containing process identification number (PID) older than 5 hours.

To do so, SSH into your remote Linux server and create a new bash file, type command:

sudo vim cleanup.sh

Add the following scripts:

Save and close the file.

Next, make the file executable, type command:

sudo chmod +x cleanup.sh

To execute the file, run command:

./cleanup.sh

Also, You can to assign the script on Cron scheduling job, type command:

crontab -e

Select Vim editor if needed and assign the script at the bottom section, similar to this:

@daily /home/ubuntu/cleanup.sh > /dev/null

Save and close the file.

Next, you can reload the Cron service, type command:

sudo service cron reload

That’s all.

Finally, this tutorial can save you time searching for quick fixes guide on how to cleanup temporary files on Linux tmp directory. Feel free to submit us an enhancement on the script as needed.

I hope this tutorial helped you and feel free to comment section below for more suggestions.

SHARE THIS ARTICLE

Tags: , , ,

Leave a Reply

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