I am using the following command on a Unix server:
find . -type f -name "*.txt" | xargs grep -li 'needle'
Since grep -R
is not available, I have to use this find/xargs solution. Every time a file cannot be opened, grep
tells me this:
grep: can't open "foo.txt"
I want to get rid of this message, so I tried to redirect stderr to /dev/null
, but somehow this is not working.
find . -type f -name "*.txt" | xargs grep -li 'needle' 2>/dev/null
I want to preserve stdout (i.e. write the results to the console), and only hide these grep error messages. Instead of 2>
, I also tried &>
, but this also did not work. How can I fix this?