LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Enterprise (https://www.linuxquestions.org/questions/linux-enterprise-47/)
-   -   Files older than 1 day not deleted with –mtime +1 (https://www.linuxquestions.org/questions/linux-enterprise-47/files-older-than-1-day-not-deleted-with-%96mtime-1-a-4175548214/)

RHCE_ran 07-17-2015 02:18 AM

Files older than 1 day not deleted with –mtime +1
 
I have set a cron job which is something like:

find <path> -iname '*.dmp' -mtime +1 -exec rm -vf {} \;

This job ran at 10 am (17th July) today but did not delete files which were created on 16th July around 2 am though it is more than 24 hours.
I hope I have been able to explain the query that why files older than 1 day are not being picked up.

Requesting a reply to my query.

Regards

cliffordw 07-17-2015 05:02 AM

Hi,

Are you sure the job ran? If so, do you have a log of it's output? It might be in your email on that machine if you didn't explicitly redirect it somewhere.

Can you confirm that the "find" is finding all the files, by running:

Code:

find <path> -iname '*.dmp' -mtime +1 -ls
Which user is running this command - root or a regular user? Could there be a problem with file permissions?

Regards,

Clifford

RHCE_ran 07-17-2015 07:34 AM

Thanks for your answer. According to my finding,

find <path> -iname '*.dmp' -mtime +0 -ls

is finding the required files accessed more than 24 hours ago but not +1.

Non-root user is running the command. There is no issue of file permissions.

Should it be

find <path> -iname '*.dmp' -mtime +0 -ls then?

Regards

rknichols 07-17-2015 11:07 AM

I guess you can be forgiven for not digging through the rather lengthy find manpage, but the answer is there.
-atime n
File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago.
-mtime n
File’s data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times.
So yes, you would need to use "+0".

cliffordw 07-17-2015 11:08 AM

Hi again,

You mention files accessed more than 24 hours ago. Are you interested in access time, or modification time ("mtime")?

The "+1" is the correct usage, and should work (assuming mtime is what you want to check).

Could you possibly run the "stat" command for one of these files, and post the output?

cliffordw 07-17-2015 11:12 AM

Quote:

Originally Posted by rknichols (Post 5392798)
I guess you can be forgiven for not digging through the rather lengthy find manpage, but the answer is there.
-atime n
File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago.
-mtime n
File’s data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times.
So yes, you would need to use "+0".

Ah, thanks for that! I misunderstood then, and learnt something new today :-)

cliffordw 07-17-2015 11:15 AM

RHCE_ran, if you're looking for files older than 24 hours exactly (which is what I though "-mtime +1" does), as opposed to files modified before yesterday, try:
Code:

find <path> -iname '*.dmp' -mmin +1440 -ls
This finds files older that 1440 minutes, which is 24 hours, and doesn't do the same rounding the -mtime does.


All times are GMT -5. The time now is 01:19 PM.