Avatar of sunsubbu
sunsubbu asked on

Remove files older 'x' duration

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
Unix OS

Avatar of undefined
Last Comment
sunnycoder

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
stefan73

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
sunnycoder

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

the only problem is that time (+3) is in minutes and not seconds
sunnycoder

find <dir> -amin +3 -type f -exec rm {}
ignore the trailing r in the last post
stefan73

sunnycoder,
> -amin

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

Stefan
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER
sunsubbu


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
ASKER
sunsubbu

Hi,

      Please share any minimum clue on this..

Thanks
Subbu
sunnycoder

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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ahoffmann

what's wrong with Stefan's perl suggestion?
sunnycoder

nothing is wrong ahoffmann ... the requirement has been modified a little