Linode.com Forum Forum Index Linode.com Forum
Linode Community Forums
 


delete a file after xx mins

Click here to go to the original topic

 
       Linode.com Forum Forum Index -> Linux, Apache, Mysql and PHP (LAMP) Forum
Author Message
Garry



Joined: 15 Oct 2003
Posts: 14

Posted: Sun May 30, 2004 12:41 pm    Post subject: delete a file after xx mins  

Hi,

I would like to be able to delete a file after 30mins, what would the could be for that to check to make sure it 30mins and older ?

Regards,
Garry
Back to top  
herculesjr



Joined: 28 May 2004
Posts: 11

Posted: Sun May 30, 2004 7:15 pm    Post subject:  

put that in crontab :)
Code:
0/30 * * * * rm file
Back to top  
smerritt



Joined: 18 Nov 2003
Posts: 30

Posted: Mon May 31, 2004 2:43 am    Post subject:  

That won't work. Say the file gets created at 00:20. Ten minutes later, at 00:30, the file gets removed, but it was only ten minutes old.

If it's a regular file, try

Code: find filename -cmin +30 -print | xargs rm

find will only output the filename if it was created at least 30 minutes ago (technically, if its ctime is more than 30 minutes ago), so if the file is newer, its filename doesn't get piped to xargs.
Back to top  
sweh



Joined: 13 Apr 2004
Posts: 234

Posted: Mon May 31, 2004 5:03 pm    Post subject:  

smerritt wrote:
Code: find filename -cmin +30 -print | xargs rm

A minor gotcha with this; if you can't trust the filenames (eg someone else could have put them in) then use "-print0" and "xargs -0" because filenames with spaces, embedded returns or other funny characters could cause problems.
Back to top  
 
       Linode.com Forum Forum Index -> Linux, Apache, Mysql and PHP (LAMP) Forum
Page 1 of 1