Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

On a Red Hat Linux system, I have a directory with several hundred files. I wanted to delete all files older than 24 hours. I did the deletion using find . -type f -mtime +1 -delete. Trivial stuff, right? Then, while checking the results, I discovered that ls -l reports files older than 24 hours in the directory. Note the date below, and the result of the last find:

> date
Sun Jan  5 19:02:43 PST 2014
> find . -type f -mtime +1 | wc -l
0
> find . -type f | xargs /bin/ls -l | grep 'Jan  3' | wc -l
70

Curiously, there are no files older than about 48 hours. (There definitely were before.) At this point, however, I'm well and truly stumped. I'm probably missing something obvious, but what? Can someone please enlighten me?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

For find, "+1" means greater than 1. Further, when computing age in days, it rounds down to the nearest integer.

This behavior is documented in the man page:

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.

In your example, those two full days means that it should have found files only if they were older than Jan 3 19:02:43. Any file made after that on Jan 3 would not be found.

So, when you wrote "Curiously, there are no files older than about 48 hours", that means that find is behaving exactly as documented, however perverse that might be.

share|improve this answer
    
The man page on the system I was running at the time (which happened to be a Mac running OS X 10.8) did not mention the "at least two days ago" part. However, the Red Hat man page does mention it, and therein lies a lesson in checking the man page on the (remote) system one is actually running a command on, not the system used on one's laptop :-(. In any case, both man pages do mention the fractional part issue, and that should have been enough to figure it out. Thank you for solving this, and the helpful info. –  mhucka Jan 6 at 6:20
    
@mhucka I have seen the issue of Mac man pages being different come up before. I'm curious whether the Mac find is different or just its Mac man page. –  John1024 Jan 6 at 6:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.