【问题标题】:Executing find command for geting all the files modified after a date执行 find 命令以获取某个日期后修改的所有文件
【发布时间】:2011-08-19 14:28:13
【问题描述】:

我使用 shell find 命令列出目录中的所有文件。它工作正常。我想列出在指定日期之后修改的所有文件,我使用了这个命令

$command='touch -date "2010-01-18" /home;find.-newer /home ';
$Getfile = exec($command,$ret,$output);

但它不起作用。提前致谢

【问题讨论】:

  • 什么不起作用,shell 命令或exec() 调用?你得到了什么?一个错误,没有输出等等......
  • 我敢打赌,如果你在 shell 中使用 that find 命令,它也不会起作用。
  • -newer 参数需要一个指向文件的指针作为参考,哪些文件应该显示为较新的文件。参见手册页File was modified more recently than file. If file is a symbolic link and the -H option or the -L option is in effect, the modification time of the file it points to is always used. 所以你必须触摸一个文件而不是一个目录,并使用这个文件作为参考,或者你只需​​要触摸并使用-cmin <minutes since last change>,因为你使用 php 很遗憾计算特定的分钟数日期。
  • @DaveRandom 我正在获取此文件夹中的所有文件
  • 您可以对此进行更精细的控制,如果/当您将脚本移植到 Windows 或其他操作系统时,不会冒破坏脚本的风险,并且如果您使用组合,则不必解析另一个命令的输出的opendir()filemtime() 来完成这项工作......

标签: php exec


【解决方案1】:

在当前目录中查找特定日期之后修改的所有文件

$command='touch -t 201001180000 /tmp/timestamp; find . -type f -newer /tmp/timestamp'

【讨论】:

  • 我可以指定另一个目录吗?
  • 绝对,$command='touch -t 201001180000 $path1;查找 $path2 -type f -newer $path1'
【解决方案2】:

您可以使用目录进行查找,但是建议的语法是 --

find ABSOLUTE_PATH -newer /home -type f

. 是当前工作目录,
(web环境下可以参考DOCUMENT_ROOT + REQUEST_URI)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-04
    • 2011-01-07
    • 2019-02-26
    • 2011-11-07
    • 2014-11-16
    • 2010-09-17
    • 1970-01-01
    相关资源
    最近更新 更多