基于修改时间在Linux中查找文件

时间:2014-04-04 06:25:52

标签: linux bash

有没有办法在Linux中获取只有修改时间大于凌晨5点的文件,假设文件是​​在同一天修改/创建的。

2 个答案:

答案 0 :(得分:2)

如果你有GNU find,那么你可以这样做:

find . -name "*" -type f -newermt "2014-04-04 05:00:00"

来自man页面:

  

-newerXY参考          将当前文件的时间戳与引用进行比较。该          引用参数通常是文件的名称(以及其中之一)          它的时间戳用于比较)但它也可能是一个          描述绝对时间的字符串。 X和Y是占位符          对于其他字母,这些字母选择属于哪个时间          如何使用参考进行比较。

   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  argu‐
   ment  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  deter‐
   mined,  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.

答案 1 :(得分:2)

您可以在最后一天找到修改过的文件find / -type f -mtime -1

##  (year 2014 April day 05 time 05:00:00)
touch -t 201404040500.00 ~/myfile

## Find all files newer then myfile 
find / -newer ~/myfile

希望有所帮助