

Here is an example screenshot of the above four commands. There are some key options you should know to use with grep. We use options to modify the way the information is presented to the user.įor example, the following command prints all those lines that contain the string linux whether upper-case, lower-case, or any other case. You can also use –ignore-case an equivalent of -i to do the case insensitive search.


The following command prints the count of all those lines that contain the string linux. The option -i searches case-insensitively while -c prints the count of lines. Another way to specify both -i and -c together is as -ic because the order and the way you use the options do not matter. The following command will print all those lines that contain the string linux along with the line numbers where the linux string was found. You can also use –line-number instead of -n. The option -o or –only-matching will only print the matching words not the complete lines. You can also print line numbers by combining -o with -n. The option -v or –invert-match will print all those lines that did not find any match. So, if you want to print all those lines that do not contain the string linux then you can use the -v option. You can use -w or –word-regexp option when you want to print all those lines that contain the string linux as a complete word, not as a substring. Command to search for text in files linux how to#.
