$ 5) Searching the line or word along with the line numbers etc/ufw/les:-A DOCKER-USER -i enp0s3-j DROP etc/ufw/les:-A DOCKER-USER -i enp0s3 -j ufw-user-input It informs the command to check all files recursively from all directories and sub-directories of the given path. Let’s assume we have files in directories and their sub-directories also have some files, we want to search words or sentences from all those files to do so we need to add hyphen r (-r).
![grep options in linux grep options in linux](https://cdn.linuxfordevices.com/wp-content/uploads/2020/03/Grep-command-in-Linux.png)
$ 4) Search words recursively from files & directories For that, we use the hyphen w (-w) option to perform such a search. What if we want to search by words only not by sub-string. In the above example, the grep command shows the output based on the sub-string. In such a case we can use the -i option to get outputs case-insensitively. Suppose we have a paragraph that contains the same words with different cases. Nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologinīy default grep command output our searched text case-sensitively. Example is shown below: $ grep nobody /etc/passwd The output will be the row containing search text or word. If our working directory and file directory are different we need to specify the file path with filename. Then, we simply need to use the grep command then specify the regex pattern or word we want to search. 1) Search text from the file.Ĭreate a new text file that contains some text.
![grep options in linux grep options in linux](https://static.javatpoint.com/linux/images/linux-grep-regular-expression4.png)
Let’s dive into examples of grep command. Regex is a sequence of characters that specifies a search pattern. The pattern implies plain text or regular expression (shortened as regex) to search matching sets of data. You can use the following command to check info on all options. Option refers to the extra parameters to invoke or access the inbuilt feature.