Use the -s
flag for suppressing error messages about unreadable file or files that don’t exist.
Consider a test.txt
file with the following content:
sad
happy
awake
coffee
work
school
Searching for “happy” with the -s
flag doesn’t really do anything special since test.txt
does in fact exist.
$ grep -s "happy" test.txt
happy
Suppose there was a typo and we typed best.txt
instead, we would see an error:
$ grep "happy" best.txt
grep: best.txt: No such file or directory
The -s
flag will suppress that error:
$ grep -s "happy" best.txt