Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to clean up a server that my webmaster let turn into a mess.

I know how to list all files not accessed within the last x days using find and -atime, but what I'm looking for is to come up with a listing of the last access date for files one level down in directory /foo:

/foo/bar1.txt Dec 11, 2001
/foo/bar2.txt Nov 12, 2008
/foo/bar3.txt Jan 12, 2004

For folders one level down in directory /foo, list the date of the most recently accessed file within the directory (no limit on depth for identifying last access date)

/foo/bar1/ Feb 13, 2012
/foo/bar2/ Oct 11, 2008

Where /foo/bar1/ has a file modified Jan 1, 1998 and Feb 13, 2012 and /foo/bar2/ has 30 files, most recent of which was accessed Oct 11, 2008.

This question is similar to: but rather than the modification date, the date of interest is the last accessed date.

share|improve this question
Was the fs mounted with the "noatime" option? If so, you're sunk. – EEAA Nov 12 '12 at 4:07
Nay. I was able to list individual files earlier/later than x days using find & -atime. – kayaker243 Nov 13 '12 at 1:52
find /foo/* \( -type d ! -name . -prune \) -exec ls -lu {} \;

find /foo/* \( -type d ! -name . -prune \) | 
while read dir
    find $dir -type f -exec  stat -c "%X %n %x" {} \; |
          sort -rn | head -1 | awk '{print $2, $3, $4}'

Try those.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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