We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Remove files older 'x' duration

sunsubbu
sunsubbu asked
on
Medium Priority
433 Views
Last Modified: 2013-12-27
Hi All,

 I want to remove files which are older than 'x' duration from the given directory

here 'x' is in seconds

any inputs would be appreciated

Thanks
Subbu
Comment
Watch Question

Top Expert 2004
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
CERTIFIED EXPERT
Top Expert 2006

Commented:
find <dir> -amin +3 -type f -exec rm {}r

the only problem is that time (+3) is in minutes and not seconds
CERTIFIED EXPERT
Top Expert 2006

Commented:
find <dir> -amin +3 -type f -exec rm {}
ignore the trailing r in the last post
Top Expert 2004

Commented:
sunnycoder,
> -amin

I think that's GNU find. Solaris find is less cozy :-/

Stefan

Author

Commented:

Hi Stefan & sunnycoder,

   Thanks for your reply, but little modification is there on my question..the question is
i want to list the files which were modified in a time interval
i.e
say for example
 we need two options. -mfrom X and -mto Y where X & Y are in seconds relative to current time

 here 'mfrom' & 'mto' are in seconds..

For example, user will give following option
              -mfrom 7200 -mto 3600
that means if script runs at 2 PM it will list the files modified between 12 to 1

If user would like to list the files modified a day before then user will give -mto 86400

any help on this is greatly appreciated

Thanks & Regards
Subbu

Author

Commented:
Hi,

      Please share any minimum clue on this..

Thanks
Subbu
CERTIFIED EXPERT
Top Expert 2006

Commented:
as Stefan said solaris find is does not provide much options but if the previous command worked for you, then try this

find <dir> -amin +3 -amin +5 -type f -exec rm {}

this will remove all file accessed between last 3 to 5 minutes

use ctime if you want modification time instead
what's wrong with Stefan's perl suggestion?
CERTIFIED EXPERT
Top Expert 2006

Commented:
nothing is wrong ahoffmann ... the requirement has been modified a little
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.