我有一个 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
。较短的查询有效。我检查了打破引号的路径,但没有。
什么没有影响:
- 将类型查询部分切换为
\( -type l -o -type f \)
. -a
在所有条件之间添加。- 添加或删除
./
路径。 - 在条件组或个别条件
\( \)
周围添加。-path
- 替换
!
为-not
没有效果
我在 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 -a
:Linux 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