So, the thing is, I'm on linux terminal using grep command and I want the output without all the lines where it prints at the beginning "grep:" or the lines that begins with "./", because now I'm getting something like this:
grep: ./users/blabla1: Permission denied grep: ./users/blabla2: Permission denied grep: ./users/blabla3: Permission denied grep: ./users/blabla4: Permission denied grep: ./users/blabla5: Permission denied grep: ./users/blabla6: Permission denied grep: ./users/blabla7: Permission denied grep: ./users/blabla8: Permission denied ./foo/bar/log.log ./foo/bar/xml.xml
I have tried this:
grep -irl "foo" . | grep -v "Permission denied"
I have also tried this one:
grep -irl "foo" . | grep -v "^grep:"
And finally this one:
grep -irl "foo" . | grep "^./"
But I keep getting same results as if I haven't put anything after the |, any ideas? What am I missing?
Exclude Words and Patterns By default, grep is case-sensitive. This means that the uppercase and lowercase characters are treated as distinct. To ignore the case when searching, invoke grep with the -i option. If the search string includes spaces, you need to enclose it in single or double quotation marks.
How to Exclude All “Permission denied” messages When Using Find Command in UNIX/LINUX? use 2>/dev/null. The 2>/dev/null at the end of the find command tells your shell to redirect the standard error messages to /dev/null, so you won't see them on screen.
When find tries to search a directory or file that you do not have permission to read the message "Permission Denied" will be output to the screen. The 2>/dev/null option sends these messages to /dev/null so that the found files are easily viewed.
How can you suppress warnings or errors, and only get search result in find command? The find command sends any error or warning message to standard error output (i.e., stderr ). So all you have to do to suppress these messages is to redirect stderr to /dev/null .
The messages you are receiving is due to a lack of permission on those files, i.e., those are error messages.
All you have to do is to redirect the stderr
(standard error output) to /dev/null
, like this:
grep -irl "foo" 2> /dev/null
To lear more about redirection (on bash), read this article: Bash Reference Manual - Redirections
Edit: You can also just suppress error messages by using:
grep -irl "foo" 2>&-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With