【发布时间】:2020-08-17 17:10:32
【问题描述】:
是否可以使用 find 来显示多个匹配不同名称格式且比日期新的文件名,而不必为 -name 的每个实例显式使用 -newer 标志?我正在尝试将嵌套在 rsync 中的 find 命令从旧脚本从文件黑名单转换为白名单(很快将有更多文件名添加到同一目录中,需要忽略)。
我正在使用作为脚本的一部分更新的锁定文件来查找 mtime 比其 mtime 更新的特定文件:
$ls -la last_script_run.lock
-rw-r--r-- 1 user users 29 Aug 10 00:00 last_script_run.lock
如果我尝试获取多个文件名,如果不对每个 -name 实例使用 -newer 标志,我将无法使其工作。
例如这有效:
find $ORIGIN -type f -name "realm_app*" -newer test/last_script_run.lock \
-or -name "realm_sys*" -newer test/last_script_run.lock
test/logfiles/realm_app_logs_2020_08_10.tgz.closed
test/logfiles/realm_app_logs_2020_08_11.tgz.closed
test/logfiles/realm_app_logs_2020_08_12.tgz.closed
test/logfiles/realm_app_logs_2020_08_13.tgz.closed
test/logfiles/realm_app_logs_2020_08_14.tgz.closed
test/logfiles/realm_app_logs_2020_08_15.tgz.closed
test/logfiles/realm_app_logs_2020_08_16.tgz.closed
test/logfiles/realm_app_logs_2020_08_17.tgz.closed
test/logfiles/realm_system_logs_2020_08_16.tgz.closed
这不是:
find $ORIGIN -type f -name "realm_system*" -newer test/last_script_run.lock \
-or -name "realm_app*"
test/logfiles/realm_app_logs_2020_08_01.tgz.closed
test/logfiles/realm_app_logs_2020_08_02.tgz.closed
test/logfiles/realm_app_logs_2020_08_03.tgz.closed
test/logfiles/realm_app_logs_2020_08_04.tgz.closed
test/logfiles/realm_app_logs_2020_08_05.tgz.closed
test/logfiles/realm_app_logs_2020_08_06.tgz.closed
test/logfiles/realm_app_logs_2020_08_07.tgz.closed
test/logfiles/realm_app_logs_2020_08_08.tgz.closed
test/logfiles/realm_app_logs_2020_08_09.tgz.closed
test/logfiles/realm_app_logs_2020_08_10.tgz.closed
test/logfiles/realm_app_logs_2020_08_11.tgz.closed
test/logfiles/realm_app_logs_2020_08_12.tgz.closed
test/logfiles/realm_app_logs_2020_08_13.tgz.closed
test/logfiles/realm_app_logs_2020_08_14.tgz.closed
test/logfiles/realm_app_logs_2020_08_15.tgz.closed
test/logfiles/realm_app_logs_2020_08_16.tgz.closed
test/logfiles/realm_app_logs_2020_08_17.tgz.closed
test/logfiles/realm_system_logs_2020_08_16.tgz.closed
虽然我提供的两个示例可以使用"realm_*" 的一个实例捕获,但我还有其他几种名称格式无法用-name 的单个实例捕获。为了简洁和可读性,我宁愿只使用一次 -type f 和 -newer $lockfile 部分。我以前使用文件黑名单让它工作:
find $ORIGIN -newer test/last_script_run.lock -type f -not -name \"*csv*\" \
-a -not -name \"*data-collection*\"
现在我正试图将其转换为白名单,我似乎无法让它工作。这是否可行,还是我需要在命令中将-newer 标志添加到-name 的每个实例?
【问题讨论】: