Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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: http://stackoverflow.com/questions/5566310/how-to-recursively-find-and-list-the-latest-modified-files-in-a-directory-with-s but rather than the modification date, the date of interest is the last accessed date.

share|improve this question
1  
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

1 Answer 1

find /foo/* \( -type d ! -name . -prune \) -exec ls -lu {} \;


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

Try those.

share|improve this answer

Your Answer

 
discard

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.