How to delete files which are more than one hour old?
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to delete files which are more than one hour old?
Users are uploading files in the server.
I need to delete them which are older than one hour.
I don't want to use php to delete.
I have written a script to delete.
While i run the script to delete via cron or manually,
php-fpm is locked or the folder is locked. I don't know exactly.
So, the website is not working during the process.
And then it starts to work.
Instead of this, is there any system method to delete the files?
But i'd be very careful before running the above since it could potentially delete a lot of files (removing everything in its path that is more then 1 hour old!)
But i'd be very careful before running the above since it could potentially delete a lot of files (removing everything in its path that is more then 1 hour old!)
Thanks for the command
Is there anyway to make it run every one hour?
The files are created by the user apache.
//EDIT
Got it. But it takes longer time to find the files.
find uploads -mmin +2880
But still it is looking for files. i haven't got any result.
It looks like a very slow command.
It is still running.
I don't see any status. There is no percentage of complete.
Can i wait or stop the execution.
Please tell me some optimized method to delete the files.
What command, exactly, did you use?
You can stop it with Ctl-C from the shell it is attached to (i.e., where you started it). Or you can get the PID of the find process using ps or top and kill it.
Before trying to delete them I would get some kind of stats on how many, how big, how old, how fast are new ones being added, what type files, what processes might have them open, directory depth, etc.. That find command running for so long and producing no results is suspicious to me.
Can you put any numbers and other parameters to those questions?
I was running a php script to delete the files every one hour. It was slow. I stopped it for the last three days.
So the files are just three days old. But there will be lot of files. I have no idea how many files are there.
I was running a php script to delete the files every one hour. It was slow. I stopped it for the last three days.
So the files are just three days old. But there will be lot of files. I have no idea how many files are there.
Well, frankly, if you cannot characterize the basic task parameters there is no way to characterize a solution, much less an optimal solution. The long running find command and your comments about the php process taking too long indicate that the problem involves much more than simply deleting a few files every hour, and the solution is likely to require more thought.
I haven't calculated them before.
I was just deleting the files.
The file size are less than one MB.
There are always in KB. (maximum file size might be 500 to 700 KB)
The files are just three days old. Because i didn't delete them in the last three days.
Per hour, there might be 2000 to 3000 files to be added. For calculation, we can double it.
So, we can assume 6000 files added. But i don't think there will be 6000 files per hour.
6000 * 24 * 3 = 4,32,000
But i am pretty sure, there won't be that much files there. (I assume there might be 30k to 40k files.)
'stat'ing 40k files is going to take time whatever method you use.
If other processes are also soaking up io bandwidth this is also going to slow down the process further.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.