Search suppression and grep cannot open output

I was given this syntax by user phi

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

I would like to suppress the output of grep: cannot open ..... and find: cannot open rows from the results.

Sample output is ignored:

 grep: can't open ./cisc/.xdbhist find: cannot open ./cisc/.ssh 
+4
source share
2 answers

Have you tried redirecting stderr to / dev / null?

 2>/dev/null 

So the above redirects stream no.2 (which is stderr) to / dev / null. It depends on the shell, but the above should work for most. Since find and grep are different processes, you may have to do this for both, or (possibly) execute in a subshell. eg.

 find ... 2>/dev/null | xargs grep ... 2>/dev/null 

Below is a link to some bash redirect documentation. If you are not using csh, this should work for most.

+12
source

Option flag grep -s will suppress these messages for the grep command

+8
source

Source: https://habr.com/ru/post/1286587/


All Articles