LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-07-2015, 10:00 PM   #1
agriz
Member
 
Registered: Nov 2011
Posts: 197

Rep: Reputation: Disabled
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?

Thanks
 
Old 07-07-2015, 10:40 PM   #2
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
As a possibility, you can use find

Code:
find /directory -mmin +60
Then maybe executing on files found
Code:
#find /directory -mmin +60 -exec rm {} \;
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!)
 
Old 07-07-2015, 11:02 PM   #3
agriz
Member
 
Registered: Nov 2011
Posts: 197

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Sefyir View Post
As a possibility, you can use find

Code:
find /directory -mmin +60
Then maybe executing on files found
Code:
#find /directory -mmin +60 -exec rm {} \;
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.

Last edited by agriz; 07-07-2015 at 11:15 PM.
 
Old 07-07-2015, 11:28 PM   #4
agriz
Member
 
Registered: Nov 2011
Posts: 197

Original Poster
Rep: Reputation: Disabled
Quote:
find uploads -mmin +2880
During this time, the website takes longer time to load.
 
Old 07-08-2015, 12:43 AM   #5
agriz
Member
 
Registered: Nov 2011
Posts: 197

Original Poster
Rep: Reputation: Disabled
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.
 
Old 07-08-2015, 12:48 AM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by agriz View Post
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.
 
Old 07-08-2015, 12:55 AM   #7
agriz
Member
 
Registered: Nov 2011
Posts: 197

Original Poster
Rep: Reputation: Disabled
I stopped it using ctrl + c now
I ran "find uploads -mmin +2880"

Do we have any better command to watch the folder and delete files?
I once read a command but i forgot the name.
 
Old 07-08-2015, 01:02 AM   #8
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
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?
 
Old 07-08-2015, 01:04 AM   #9
agriz
Member
 
Registered: Nov 2011
Posts: 197

Original Poster
Rep: Reputation: Disabled
Sir,

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.
 
Old 07-08-2015, 01:10 AM   #10
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by agriz View Post
Sir,

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.
 
Old 07-08-2015, 01:15 AM   #11
agriz
Member
 
Registered: Nov 2011
Posts: 197

Original Poster
Rep: Reputation: Disabled
Sir,

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.)
 
Old 07-08-2015, 01:38 AM   #12
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,876

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
'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.
 
Old 07-08-2015, 02:03 AM   #13
agriz
Member
 
Registered: Nov 2011
Posts: 197

Original Poster
Rep: Reputation: Disabled
Is there anyway to clean it up regularly without slowing down?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find files 1 hour older in perl script renuk Linux - Newbie 2 12-17-2013 06:58 AM
Cron job issue - every hour works, but specific hour fails lunarleviathan Linux - Newbie 6 11-20-2009 12:19 AM
Can I delete files in /mnt/tmp? and Files in the trash can will not delete? M$ISBS Slackware 15 10-02-2009 11:56 PM
FIND files modified 1 hour before sachinh Linux - General 3 05-20-2006 04:42 AM
change clock from 24 hour to 12 hour in suse 9.2/KDE 3.3 jmlumpkin Linux - Newbie 1 01-22-2005 11:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration