Ubuntu – Grep, ignore warnings

grepsearch

I am trying to find the installation directory of a particular package. I have a certain keyword using which I am trying to find a particular file.

During grep, I only want to include cpp or h file type. I do not want the grep to show warnings like Permission Denied or Could not find the Directory.
I just want it to display matched files, nothing else. Please suggest how can I do this?

At present I am using

grep "My term" -ir --exclude-dir="\.svn" --include=*.{cpp,h} ./

Best Answer

Those warnings are directed to the stderr stream, as opposed to the standard out file descriptor. You can silence the stderr output by adding 2>/dev/null to the end of your command.

Related Question