在linux中列出具有上次访问date的文件

我想清理一个服务器,让我的网站pipe理员变成一团糟。

我知道如何使用find和-atime来列出最近x天内没有访问的所有文件,但是我正在寻找的是在/foo目录下一级文件的最后访问date列表:

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

对于目录/foo下一级文件夹,列出目录中最近访问的文件的date(对于识别上次访问date没有深度限制)

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

其中/foo/bar1/具有1998年1月1日和2012年2月13日修改的文件,而/foo/bar2/有30个文件,其中最近一次访问是2008年10月11日。

这个问题类似于: https : //stackoverflow.com/questions/5566310/how-to-recursively-find-and-list-the-latest-modified-files-in-a-directory-with-s ,而不是修改date,感兴趣的date是最后访问的date。

 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 

试试这些。