linux - 查找在日期范围之间创建的文件

我在工作中通过 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更改为aBc中的任何一个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.

https://stackoverflow.com/questions/18339307/

相关文章:

linux - 如何安排 tcpdump 在特定时间段内运行?

linux - 须藤 : docker-compose: command not found

linux - 将时间跨度(以秒为单位)转换为 shell 中的格式化时间

linux - 无法在 Ubuntu 16.04 中启动 Docker 服务

linux - 从标准输出中获取输出的最后 4 个字符

java - 无法创建Java虚拟机

linux - 如何将 bash 别名定义为多个命令的序列?

linux - 分别对每个文件进行 GZip

linux - 使用 ssh 检查远程主机上是否存在文件

linux - 将标准输出作为命令行工具的文件名传递?