If you want the files in a given directory sorted by modification age (most recent first):
To sort by access time, add the
However, beware that modern Linux systems do not track exact access times by default. So the access timestamps may not be reliable.
If you want to find the most recent file within a directory tree, including subdirectories, the easiest method by far is to use zsh's glob qualifiers.
print -lr -- **/*(om)
oa instead of
om to use the access time rather than the modification time. You can restrict the matches, for example to get the 10 most recent files:
print -lr -- **/*(om[1,10])
Those skip hidden files. If you want to also consider hidden files, add the
D glob qualifier. You can also add the
. glob qualifier to only consider regular files (not consider symlinks, directories, fifos...), and
mh-1 to restrict to files last modified within the last hour.