0

I'm trying to find all files that haven't been touched for 6 months or longer. I ran this command but it just shows all files that were edited 6 months a go.

find . -type f -mtime 183 -exec ls -latr {} \;

How would I make this so it's 6 months or more?

1
  • -mtime +183 would be for files whose age rounded up to the next 24 hour unit is strictly greater than 183. So that includes files modified 183*24*3600+0.00000001 seconds ago and older. Oct 4 '16 at 12:10
3

-mtime 183 is for files whose age rounded up to the next 24-hour period is equal to 183, so for ages comprised between 182*24*3600 seconds (exclusive) and 183*24*3600 seconds (inclusive) (where seconds are Unix seconds, that is have a variable duration that is the 86400th part of the earth day, not the fixed duration ISO definition of the second. So all days are 86400 seconds, we don't need to account for leap seconds).

With -mtime +183, you get files whose age rounded up to the next 24 hour period is strictly greater than 183, so that for ages strictly greater than 183*24*3600 seconds.

Note that 24 hour period is not necessarily the same as day because of daylight saving time switches in some regions.

With some find implementations (FreeBSD, GNU), you can also use ! -newermt '6 months ago'. mt compares the modification time with the time given as argument.

That will give files modified before the same day of the month, same hour 6 months ago, but in the case of GNU find (as opposed to FreeBSD) it doesn't do the DST adjustment (in timezones where DST applies), that is it gives you the information as if in a UTC timezone. If now is 2016-07-01 13:00 (summer time), FreeBSD find would report files last modified before 2016-01-01 13:00 (winter time), while GNU find would report files last modified before 2016-01-01 12:00 (winter time). There might be variations as well when called on the 29th, 30th or 31st of the month and the month 6 months ago has no such date.

2

Add a + in front of the day value. From the man page:

   Numeric arguments can be specified as

   +n     for greater than n,

   -n     for less than n,

   n      for exactly n.

and

... 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.

Although this refers to the atime test, it is the same for the mtime and ctime tests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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