查找命令查找在Linux / Cygwin下特定日期之后创建的目录

时间:2013-12-13 16:04:33

标签: linux bash find cygwin

我想使用find命令查找这些目录:

Access: 2013-12-13 10:59:46.190886900 -0500
Modify: 2013-12-03 07:04:02.995890600 -0500
Change: 2013-12-03 07:04:02.995890600 -0500
 Birth: 2013-12-02 07:04:02.000000000 -0500  (I want a time after '12-03')

这是我运行的命令,但它仍然列出了较旧的目录:

find . -type d -newerBt '2013-12-03 00:00:00' -exec du -h {} \;

如何修改此行以查找在该日期之后创建的目录? -newerct和-newerBt之间有什么区别?我想我想要出生日期。

注意:我使用最新的cygwin运行它。

3 个答案:

答案 0 :(得分:3)

您可以改为使用 stat

 find . -type d -exec bash -c '(( $(stat -c %W "{}") > $(date +%s -d '2013-12-03') )) && du -h "{}"' \;

答案 1 :(得分:1)

您是finding目录,但显示中包含的文件。

这些文件的出生日期可能位于之前包含目录的出生日期。例如,创建一个文件,然后创建一个目录,并将该文件移动到该目录中。

这是出生日期和更改日期之间的差异。如果将文件移动到目录中,则会更改目录,因此我认为-newerct是您想要的。

答案 2 :(得分:0)

我想知道它是否是TimeZone问题?什么是echo $TZ?如果您在unset TZunsetenv TZ(和csh)并重新尝试相同的命令,会发生什么?

这里是-newerXY的手册页摘录。也许读它会引发一些想法?

 -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.