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

标签 linux find aix

我在工作中通过 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.

关于linux - 查找在日期范围之间创建的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18339307/

相关文章:

shell - 从编译的二进制文件创建 RPM 规范文件

php - iptables 不由 Apache 在 php 文件上执行

javascript按值在数组中查找对象并追加附加值

c++ - 使用迭代器在字符串中查找子字符串

python - -1 在这段代码中是什么意思([file for file in os.listdir(folder_dir) if file.find ("xlsx") != -1])?

c - fgetc 不识别 EOF

java - AIX - 无法创建 VM 线程。系统资源不足

python - 创建函数以规范化路径然后加入

自定义 Linux 内核系统调用包装函数

linux - Fortran OPEN 调用在 NFSv3 和 NFSv4 上有所不同