Fastest way to get creation and last modification times of a lot of files
A Posix file system node typically has three time attributes:
-
atime
(access time) -- when was the file last read -
mtime
(modification time) -- when was it last written to. -
ctime
(change time) -- when was its inode (metadata) changed.
The ctime
attribute is frequently misunderstood as creation time, and sometimes it is, which tends to confuse people.
POSIX shells have no standard way of extracting these three attributes, and you will depend on the ls
command. ls -l $file
by default shows modification time.
-
ls -lc $file
showsctime
-
ls -lu $file
showsatime
It is recommended to use ls --time-style=full-iso
or another iso format for consistent output, if you are on a GNU/linux system.
In Perl and other scripting languages, it's easier to stat()
a file and access its attributes. Perl even has the -M
, -A
, and -C
operators that return mtime
, atime
, and ctime
for a file system object. Note the time offset, though. Perl tends to report times relative to the process start time.
Related videos on Youtube
EranSch
Updated on September 18, 2022Comments
-
EranSch over 1 year
I've been having trouble finding references to this concept in the documentation so I figured I'd ask here. We're working with some boolean query logic and I've been working on building a
$match
stage with something like the following:{ '$match': { '$or': [ { depth: { '$or': [ { '$gt': 1 }, { '$lte': 36 }, { '$ne': 15 } ] } }, { height: { '$and': [ { '$gt': 1 }, { '$lte': 36 }, { '$ne': 15 } ] } } ] } },
Can anyone confirm if this type of nested boolean logic is supported?
In my testing, it doesn't return any results but it also doesn't raise any exceptions.
Thanks!
-
Ignacio Vazquez-Abrams almost 12 yearsCreation time doesn't exist in POSIX/SUS.
-
-
asdasdasd almost 12 years"Changed" and "modified", are they not synonyms?
-
Sirch almost 12 yearsIf the files permissions, ownership, gets changed, then that will update the ctime, but not the mtime.
-
Sirch almost 12 yearsAnd I just logged into AIX, im afraid
stat
wasnt there... sorry, im an AIX smitty noob. -
Ignacio Vazquez-Abrams almost 12 years"metadata change time"
-
Sirch almost 12 years"inode" change time.
-
Adam Luchjenbroers about 8 yearsIf on AIX, check for istat instead.
-
EranSch almost 7 yearsThanks for the reply. I don't think this completely achieves my goal, however, as I'm hoping to be able to combine booleans. I've updated my example to hopefully better illustrate my needs.
-
EranSch almost 7 yearsAhhh that makes perfect sense. Thank you for clarifying! Marking this as the accepted answer.