find对查找比 X 天前修改得更多的文件有很好的支持,但是我怎样才能find找到在某个日期之前修改的所有文件?
我在find手册页中找不到任何内容来执行此操作,只能与另一个文件时间进行比较或检查创建时间与现在之间的差异。制作具有所需时间的文件并与之比较是唯一的方法吗?
Den*_*son 69
不,您可以使用日期/时间字符串。
来自man find:
-newerXY reference
将当前文件的时间戳与参考进行比较。引用参数通常是文件的名称(其中一个时间戳用于比较),但它也可以是描述绝对时间的字符串。X 和 Y 是其他字母的占位符,这些字母选择属于如何使用参考进行比较的时间。Run Code Online (Sandbox Code Playgroud)a The access time of the file reference B The birth time of the file reference c The inode status change time of reference m The modification time of the file reference t reference is interpreted directly as a time
例子:
find -newermt "mar 03, 2010" -ls
find -newermt yesterday -ls
find -newermt "mar 03, 2010 09:00" -not -newermt "mar 11, 2010" -ls
Run Code Online (Sandbox Code Playgroud)
nEJ*_*EJC 38
与问题没有直接关系,但对于一些在这里绊倒的人来说可能很有趣。
find命令不直接支持 -older 参数来查找早于某个所需日期的文件,但您可以使用 negate 语句(使用已接受的答案示例):
touch -t 201003160120 some_file
find . ! -newer some_file
Run Code Online (Sandbox Code Playgroud)
将返回早于提供日期的文件。
小智 28
如果您只有“-newer 文件”,则可以使用以下解决方法:
# create 'some_file' having a creation date of 16 Mar 2010:
touch -t 201003160120 some_file
# find all files created after this date
find . -newer some_file
Run Code Online (Sandbox Code Playgroud)
男人触摸:
-t STAMP
use [[CC]YY]MMDDhhmm[.ss] instead of current time
Run Code Online (Sandbox Code Playgroud)
假设您的触摸具有此选项(我的是触摸 5.97)。
mar*_*s_b 14
find <dir> -mtime -20
Run Code Online (Sandbox Code Playgroud)
此 find 命令将查找过去 20 天内修改过的文件。
您可以添加其他限制,例如:
find <dir> -mtime -20 -name "*.txt"
Run Code Online (Sandbox Code Playgroud)
和以前一样,但只找到以“.txt”结尾的文件。
小智 6
补充一下 - 您甚至可以使用两个 newermt 参数在一个时间间隔内进行搜索:
find ! -newermt "apr 01 2007" -newermt "mar 01 2007" -ls
Run Code Online (Sandbox Code Playgroud)
查找 2007 年 3 月以来的所有文件。
find ! -newermt \xe2\x80\x9c<DATE>\xe2\x80\x9d\nRun Code Online (Sandbox Code Playgroud)\n\n像这样:
\n\nfind ! -newermt \xe2\x80\x9cjan 01 2015\xe2\x80\x9d \nRun Code Online (Sandbox Code Playgroud)\n\n这将为您提供当前目录中早于 2015 年 1 月 1 日的文件。
\n\n\n| 归档时间: |
|
| 查看次数: |
118799 次 |
| 最近记录: |