Note "ls -Flc" appears to give ctime, not "modification time" mtime. It's actual usage varies greatly depending on your OS and is generally when the file's *status* changes, not the file data itself. See perldoc -f stat and especially "perldoc perlport" and then look for 'ctime' in the stat entry. Generally, atime >= mtime since it is the last access time or the modification time, whichever is more recent.
FWIW, depending on what you are trying to do, it may be impossible to guarantee that mtime/atime/ctime will be usefull. For example if users can touch files with arbitrary dates (e.g. using touch or "tar -xf" to dearchive a tree), then you have no real way of determining age based on atime or mtime (and perhaps ctime). | [reply] |
Hey, Bluto, Thanks for the answer. I've had several responses explaining how I've misinterpreted, mishandled, and/or misused the data returned by stat(). Maybe I'll revisit it.
OTOH, things on the "ls" front keep getting more and more confusing. I've been using ls with the -u flag for "access time" and the -c flag for "modification time."
Now it seems that what I *might* want is the default time returned by ls without any date-related flag because the -c flag hooks things like chmod, chown, etc., while the default hooks only changes to the file's data. Hmmm.....
Thanks again!
| [reply] |
Maybe you're getting the ctime by accident? stat works fine for me:
atime:
>perl -le "print(scalar(localtime((stat('somefile'))[8])));"
Mon Sep 27 12:06:06 2004
mtime:
>perl -le "print(scalar(localtime((stat('somefile'))[9])));"
Fri Sep 24 18:39:39 2004
ctime:
>perl -le "print(scalar(localtime((stat('somefile'))[10])));"
Tue Dec 16 17:17:50 2003
Or maybe you are using stat on link? Compare stat vs lstat.
| [reply] [d/l] |