shell - 为什么 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
。较短的查询有效。我检查了打破引号的路径,但没有。
什么没有影响:
- 将类型查询部分切换为
\( -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
解决方案
推荐阅读
- java - Java 2d:减慢旋转速度(就像命运之轮)
- php - 如何上传图片随机名称?
- javascript - 强制 selectize.js 仅显示以 Shiny 中的用户输入开头的选项
- python - tensorflow-gpu 从 systemd 服务初始化失败
- c# - 无法删除对象,因为在删除项目时ObjectStateManager错误中找不到
- asp.net - 将 ZK 考勤设备的数据与 Web 应用程序集成和同步
- c++ - 如何使循环帐户多次出现?
- android - 如何让 StringRequestVolley 等待响应?
- c# - 为什么 ArcGIS Runtime SDK for .Net 同步地理数据库异常抛出“”
- r - 如何将外生输入添加到 nnetTs 函数?