gpt4 book ai didi

unix - 抑制 find & grep "cannot open"输出

转载 作者:行者123 更新时间:2023-12-04 16:26:38 25 4
gpt4 key购买 nike

我得到了 this用户语法 phi

find . | awk '!/((\.jpeg)|(\.jpg)|(\.png))$/ {print $0;}' | xargs grep "B206"

我想抑制 grep: can't open..... 和 find: cannot open lines from the results.sample 输出被忽略的输出:
grep: can't open ./cisc/.xdbhist
find: cannot open ./cisc/.ssh

最佳答案

您是否尝试将 stderr 重定向到/dev/null ?

2>/dev/null

因此,上面将流 no.2(即 stderr)重定向到/dev/null。这取决于 shell,但以上应该适用于大多数情况。因为 find 和 grep 是不同的进程,所以您可能必须对两者都执行此操作,或者(可能)在子 shell 中执行。例如
find ... 2>/dev/null | xargs grep ... 2>/dev/null

Here's关于 bash 重定向的一些文档的引用。除非您使用 csh,否则这应该适用于大多数情况。

关于unix - 抑制 find & grep "cannot open"输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1028885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com