LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 08-30-2005, 02:20 AM   #1
Azhrarn
Member
 
Registered: Aug 2005
Location: Europe
Posts: 63

Rep: Reputation: 15
Automatic file deletion


Hi,

got a folder empying after 48 hours with this command

find /raid/shared/ -mtime +2 -type f -exec rm -rf {} \;

Deletes all files created 2 days before the current day.

Problem is, this folder is used internally for file exchange, and I need it to delete all files which were copied to this folder more than two days ago, not files which were created more than two days ago.

In other words, if I have a file from '99, and I copy it to the folder, the script would delete it on the hour (its in cron.hourly), however, I need it to delete it in two days time.

Any help plz? I m on Red Hat 9.

Thanks!
Paul
 
Old 08-30-2005, 02:50 AM   #2
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
The simplest solution I see is to do all copies to this directory *without* preserving the creation date, so your file from '99 will become a file from '05.

But were it for me, I wouldn't be satisfied with such a solution... Maybe you could use the access time instead of the modification time.

Yves.
 
Old 08-30-2005, 03:47 AM   #3
Azhrarn
Member
 
Registered: Aug 2005
Location: Europe
Posts: 63

Original Poster
Rep: Reputation: 15
Yeah, was thinking that, but not sure hot to come about it...
Ciao
 
Old 08-30-2005, 04:09 AM   #4
oneandoneis2
Senior Member
 
Registered: Nov 2003
Location: West Sussex, England
Distribution: Gentoo
Posts: 1,457

Rep: Reputation: 45
You could set up a script that, say once an hour, examined the directory for files that had appeared since the last time the script was run & saved the information.

Then you'd know, to within one hour, which files were added when, and could delete the ones that had been there for over 48 hours.
 
Old 08-30-2005, 04:48 AM   #5
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
Yes, you're right oneandoneis2. It's a good solution.

As for the "access time" solution, it seems you just have to replace "mtime" by "atime" in your find command.

Yves.
 
Old 08-30-2005, 05:01 AM   #6
Azhrarn
Member
 
Registered: Aug 2005
Location: Europe
Posts: 63

Original Poster
Rep: Reputation: 15
Thx guys
Works like a dream!
Ciao
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File Deletion mhkhalqani Linux - General 1 10-12-2005 03:08 AM
Another question on automatic file deletion Azhrarn Linux - Newbie 1 08-29-2005 11:18 AM
File Deletion Script disinformation Linux - Software 3 04-18-2005 07:00 AM
Automatic deletion of spam folder? RKris Linux - General 1 05-27-2003 08:21 AM
Perl and file deletion berry Programming 4 05-29-2002 06:42 AM


All times are GMT -5. The time now is 02:48 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration