使用 -exec 和 -mtime 运行“find”命令时参数无效

t.f*_*kas 3 find exec mtime

Centos 上出现了相当奇怪的错误消息。

我尝试运行这个命令:

find /tmp/something -type f -mtime +2h -exec cp '{}' /tmp/target \;
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

find: invalid argument `-exec' to `-mtime'
Run Code Online (Sandbox Code Playgroud)

其他发行版上的“查找”会有所不同吗?

alp*_*tor 5

-mtime使用了几天,如果您需要 2 小时,请检查以下内容:

find /tmp/something -type f -mmin +120 -exec cp '{}' /tmp/target \;
Run Code Online (Sandbox Code Playgroud)

mmin 指定分钟,因此 -mmin +120 将过滤 120 分钟前(2 小时)之前的内容。从手册中:

-mtime n

文件数据最后一次修改是在 n*24 小时前。请参阅 -atime 的注释以了解舍入如何影响文件修改时间的解释。

-mmin n

文件数据最后一次修改是在 n 分钟前。