如何忽略警告,但保留“查找”中的错误消息

IQA*_*eas 7 bash find symlink

我正在尝试运行find命令,由于文件夹的设置方式,我在脚本中多次收到以下警告:

\n
find -L ./server/ -type f -printf '%s %p\\n' | <rest of really long complicated script>\n
Run Code Online (Sandbox Code Playgroud)\n

输出

\n
find: File system loop detected; \xe2\x80\x98./server/~andreas/root\xe2\x80\x99 is part of the same file system loop as \xe2\x80\x98./\xe2\x80\x99.\nfind: File system loop detected; \xe2\x80\x98./server/~bob/root\xe2\x80\x99 is part of the same file system loop as \xe2\x80\x98./\xe2\x80\x99.\nfind: File system loop detected; \xe2\x80\x98./server/~charles/root\xe2\x80\x99 is part of the same file system loop as \xe2\x80\x98./\xe2\x80\x99.\n...\n
Run Code Online (Sandbox Code Playgroud)\n

我知道为什么我会收到这些消息。这些符号链接是故意放置在那里供其他脚本使用的,因此我想安全地忽略控制台输出中的这些警告。

\n

如何防止find显示“检测到文件系统循环”之类的警告,但仍保留所有“真实”错误消息?

\n

我不能只是告诉find忽略每个名为 的目录root。find 有一个-nowarn选项,但无论我把它放在哪里,我都无法让它工作。到目前为止我还没有找到查找的“日志级别”选项。

\n

zac*_*kse 4

如果您使用的是 bash shell,则可以使用输出重定向通过过滤 stderr 来抑制特定错误消息grep

find ... 2> >(grep -v "File system loop detected") | ...
Run Code Online (Sandbox Code Playgroud)

bash 手册/手册页的“进程替换”部分对此进行了描述: https: //www.gnu.org/software/bash/manual/html_node/Process-Substitution.html#Process-Substitution