Why does "find -mtime" not work as expected on files with different timezones?
Solution 1:
It's possible that the time zone issue is a red herring.
find . -mtime 7
should find files that are exactly seven days old ("seven" meaning between 7.000 and 7.999 days, give or take, and "old" meaning "since last modification"). If you want files that are more than seven days old, which judging by the date on your first file (June 2010) you do, try
find . -mtime +7
I agree with you about the apparent timezone being odd, but I think it's explicable. man stat
is clear that a time_t is stored, as Sean R says below. What ls
is doing is displaying that as a local time, and it's being kind enough to take account of local daylight-saving conventions when it does so.
My system is the same: file times which happen to fall in Mar-Oct are shown with a +0100 timezone while those which fall in Oct-Mar are shown with a +0000 timezone, not because this is stored in the file system, but because the time zone file tells my system that in June, when I touched the file, I would have done it at a time that I thought was 8am, not it-would-be-7am-if-it-were-winter. ls
is kind enough, when displaying times that happen to be in summer, to show them as they would have appeared in summer, that's all.
If you can find any time zones in your ls
output that aren't either summer or winter according to your local convention, then I'm wrong - but I can't find any on my system.
Solution 2:
With find, -mtime works in 24 hour periods so
-mtime 0 or -mtime -1 mean today
-mtime 3 would mean 3 days old
-mtime +1 means greater than one day old
-mtime -7 means less than 7 days old
Solution 3:
To explain the time zone portion of it a bit more (the "mtime" discussion is handled by other comments)...
Date and times are stored on files as seconds since midnight January 1, 1970, UTC. Meaning there is no time-zone associated with them. Programs then use the system timezone setting in /etc/timezone
, unless overridden by the "TZ" environment variable, to display that time in the local timezone:
chats:/tmp$ touch foo
chats:/tmp$ ls -l foo
-rw-r--r-- 1 jafo jafo 0 Dec 1 06:14 foo
chats:/tmp$ TZ=GMT ls -l foo
-rw-r--r-- 1 jafo jafo 0 Dec 1 13:14 foo
chats:/tmp$
Note in the last line it is showing 1:14 pm, and in the output above it, where I am using my default timezone of US Mountain time (GMT-0700) it is showing 6:14 am. The difference is the second "ls" I set the TZ environment variable to GMT.
You may want to use "stat" to examine all the time/dates associated with files as well.