Question
In the second lesson on the grep
command we find explanations of the arguments -R
, for recursive searches, and -l
, for outputting matching files only. What are other useful arguments for us to pass to grep
?
Answer
A complete list of arguments to grep
can be found in the so called man (short for manual) page for the function. This entry can be found by searching something along the lines of “grep man page”. For now I will provide three commands that come in handy often.
-
-e
. Sincegrep
stands for global regular expressions, there should be some way to search with regular expressions instead of simply searching for exact string matches as we have been doing.-e
enables us to do just that. -
-v
. This useful argument allows you to search for non-matches. So it is the inverse of the usual behavior ofgrep
. -
-i
. This argument allows you to search for a match in a case-insensitive way. So for example, “hit”, “HIT”, and “HiT” all match a search for “hit”.