Find command find directories that were created after a certain date under Linux/Cygwin

天涯浪子 提交于 2021-02-05 02:36:52

问题


I want to use the find command to find these directories:

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')

This is the command I ran but it still lists older directories:

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

How can I modify this line to find the directories created after that date? What is the difference between -newerct and -newerBt. I think I want the birth date.

Note: I am running this with the latest cygwin.


回答1:


You could use stat instead:

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



回答2:


You are finding directories, but showing files contained therein.

Those files may have birth dates that lie before that of the containing directory. For example, create a file, then a directory, and move the file into that directory.

This is the difference between birth date and change date. If a file is moved into the dir, the dir is changed, so I think -newerct is what you want.




回答3:


I wonder if it's a TimeZone issue? What is echo $TZ? What happens if you do unset TZ (and unsetenv TZ, too, in csh) and re-try the same commands?

Here's the man page excerpt for -newerXY. Maybe reading it will trigger some thoughts?

 -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/20570808/find-command-find-directories-that-were-created-after-a-certain-date-under-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!