我在工作中通过 telnet 使用 AIX,我想知道如何在日期范围内的特定文件夹中查找文件。例如:我想查找文件夹 X 中在 2013 年 8 月 1 日到 2013 年 8 月 31 日之间创建的所有文件。
观察:
- 一旦我在服务器上拥有的用户角色不允许我创建文件,
touch
技巧(在其中创建两个空文件以使用 -newer 选项)对我不起作用. - 我需要在特定日期之间查找,而不是几天(例如:创建时间超过 30 天的文件,等等...)
最佳答案
如果你使用 GNU find
,从 4.3.3 版本开始你可以这样做:
find -newerct "1 Aug 2013" ! -newerct "1 Sep 2013" -ls
它将接受 GNU date -d
接受的任何日期字符串。
您可以将-newerct
中的c
更改为a
、B
、c中的任何一个
或 m
用于查看 atime/birth/ctime/mtime。
另一个示例 - 列出 2017 年 11 月 6 日 17:30 到 22:00 之间修改的文件:
find -newermt "2017-11-06 17:30:00" ! -newermt "2017-11-06 22:00:00" -ls
来自 man find
的完整详细信息:
-newerXY reference
Compares the timestamp of the current file with reference. The reference argument is normally the name of a file (and one of its timestamps is used
for the comparison) but it may also be a string describing an absolute time. X and Y are placeholders for other letters, and these letters select
which time belonging to how reference is used for the comparison.
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
Some combinations are invalid; for example, it is invalid for X to be t. Some combinations are not implemented on all systems; for example B is not
supported on all systems. If an invalid or unsupported combination of XY is specified, a fatal error results. Time specifications are interpreted as
for the argument to the -d option of GNU date. If you try to use the birth time of a reference file, and the birth time cannot be determined, a fatal
error message results. If you specify a test which refers to the birth time of files being examined, this test will fail for any files where the
birth time is unknown.
关于linux - 查找在日期范围之间创建的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18339307/