我正在尝试运行find
命令,由于文件夹的设置方式,我在脚本中多次收到以下警告:
find -L ./server/ -type f -printf '%s %p\\n' | <rest of really long complicated script>\n
Run Code Online (Sandbox Code Playgroud)\n输出
\nfind: 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
显示“检测到文件系统循环”之类的警告,但仍保留所有“真实”错误消息?
我不能只是告诉find
忽略每个名为 的目录root
。find 有一个-nowarn
选项,但无论我把它放在哪里,我都无法让它工作。到目前为止我还没有找到查找的“日志级别”选项。
如果您使用的是 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
归档时间: |
|
查看次数: |
4382 次 |
最近记录: |