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
ASKER CERTIFIED SOLUTION
Avatar of stefan73
stefan73
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of sunnycoder
sunnycoder
Flag of India image

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

the only problem is that time (+3) is in minutes and not seconds
Avatar of sunnycoder
sunnycoder
Flag of India image

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

sunnycoder,
> -amin

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

Stefan
Avatar of sunsubbu
sunsubbu

ASKER


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
Avatar of sunsubbu
sunsubbu

ASKER

Hi,

      Please share any minimum clue on this..

Thanks
Subbu
Avatar of sunnycoder
sunnycoder
Flag of India image

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
Avatar of ahoffmann
ahoffmann
Flag of Germany image

what's wrong with Stefan's perl suggestion?
Avatar of sunnycoder
sunnycoder
Flag of India image

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

Unix is a multitasking, multi-user computer operating system originally developed in 1969 at Bell Labs. Today, it is a modern OS with many commercial flavors and licensees, including FreeBSD, Hewlett-Packard’s UX, IBM AIX and Apple Mac OS-X. Apart from its command-line interface, most UNIX variations support the standardized X Window System for GUIs, with the exception of the Mac OS, which uses a proprietary system.

33K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo