1838163 Members
3392 Online
110124 Solutions
New Discussion

Re: mtime

 
himacs
Super Advisor

mtime

Hi Admns,

I want to delete files 1 day old.Can i use mtime +1 along with find command for the same?

regards
himacs
8 REPLIES 8
Dennis Handly
Acclaimed Contributor

Re: mtime

-mtime +1 will delete files two or more days old:
find path -mtime +1 -exec rm -rf +
Johnson Punniyalingam
Honored Contributor

Re: mtime

cd /folder_name

find . -mtime +1 -exec ll {} \; -> list file older than 1 day

find . -mtime +1 -exec rm -rf {} \; -> delete /remove files older than 1 day
Problems are common to all, but attitude makes the difference
Bill Hassell
Honored Contributor

Re: mtime

Just in case there are old directories, I would use rm -f rather than rm -rf. And if you really want to remove files only then add -type f to the find command:

(always look at the selection first)
find . -type f -mtime +1 -exec ll {} +

find . -type f -mtime +1 -exec rm -f {} +


Bill Hassell, sysadmin
himacs
Super Advisor

Re: mtime

Admins,

Actually i set -mtime +1 to delete the 1 day old files..but its deleteing 2 days old files..

regards
himacs
Johnson Punniyalingam
Honored Contributor

Re: mtime

Actually i set -mtime +1 to delete the 1 day old files..but its deleteing 2 days old files..

can you post the "command" ?

its better to ll -list file before you delete them so that you can double check your excution
Problems are common to all, but attitude makes the difference
R.K. #
Honored Contributor

Re: mtime

Hi Himacs,

-mtime +5 more than 5 days
-mtime -5 for less than 5 days
-mtime 5 for exactly 5 days

Regds..
Don't fix what ain't broke
Dennis Handly
Acclaimed Contributor

Re: mtime

>I set -mtime +1 to delete the 1 day old files but it's deleting 2 days old files.

That's what I said, +1 means two or more. Unless you use:
UNIX95=FIDDLE_WITH_FIND_TIMES find ... -mtime +1 ...
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1389161
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1306285
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1271016

Steven Schweda
Honored Contributor

Re: mtime

> [...] Can i use mtime +1 along with find
> command [...]

Why not try a Forum search for keywords like,
say,
find mtime
and learn all this for yourself?

Look first, ask later? Only a thought.