Ubuntu Linux:在特定时间之间查找文件?


19

我找到了一个称为“ 查找/复制”的SO ,可以在一天中的特定时间搜索文件

基于此和一个名为Grep命令的Unix SE 查找包含文本字符串的文件并将其移动,我最终得到了:

find . -type f -mtime -20 | grep -v -e " \(0[012345]\|18\|19\|2[0123]\)" | xargs mv -t daytime/

但是它正在移动所有文件。我使用Ubuntu会有所不同吗?

我要做的就是将上午6点至下午6点之间的所有文件移动到另一个目录。任何建议,将不胜感激。

Answers:


32

实际上,find已经具有此功能:

find . -newermt "2013-01-01 00:00:00" ! -newermt "2013-01-02 00:00:00"

从联机帮助页:

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

谢谢@msdl,我没有意识到这一点。似乎只给今天的日期加上“ 08:00:00”(不带日期),因此似乎每次需要一天。但这会帮助我-谢谢!
digitaltoast

那么如何在终端中打印这些文件?我尝试了此命令,但没有为我打印任何内容!
库拉桑加尔2014年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.