首页 > 解决方案 > 为什么 GNU 会找到它被告知不要的匹配文件?(在一个大查询中)

问题描述

我有一个 GNU 查找命令

find . -type l,f ! -path './bin/ash' <600 more condition like ! -path './bin/mv'> -printf "rm %P\n"

它在带有bin/ash文件(符号链接)的目录中运行。

问题:find打印rm bin/ash。为什么这样做?

find应该添加顺序条件-a,而不是-o。较短的查询有效。我检查了打破引号的路径,但没有。

什么没有影响:

我在 GNU find 中遇到了错误,还是我遗漏了什么?

find (GNU findutils) 4.7.0
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2)

更新:MCVE。在我的 Ubuntu 20.04 机器上,我执行以下操作:

cd /usr/bin/
find . -type l,f > ~/mcve.txt
FIND_CONDITION=$(cat ~/mcve.txt | xargs printf " ! -path '%s' " | paste -s)
find . -type l,f ${FIND_CONDITION} -printf "rm %P\n"

最后一个命令打印所有 2150 个文件/符号链接/usr/bin/

uname -aLinux MyHostname 5.8.0-36-generic #40~20.04.1-Ubuntu SMP Wed Jan 6 10:15:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

标签: shellshgnu-findutils

解决方案


推荐阅读