
Here we will search for the word "unix" among all the files in the Documents directory.įor this, use the below command − ~$: grep unix sample1 sample2 sample3 It comes under case-sensitive search if you have to find exact words and patterns using grep on files. Matching the Case-Sensitive Search on Files Now, we will search for these sample files through the different options of the grep command in Linux. Let's create some sample files in the 'Documents' directory and match for a string or a regular expression in those files. The grep command is pre-installed in most Linux distributions. Using Grep on Files that Match Specific Criteria on Linux

In this short guide, we will use a grep on files that match specific criteria on Linux. So you have to use the -o option only to display the name of the file and the searched character. The Grep command displays the whole line that contains the specific character. You must use quotation marks in the grep command to search for a character with a special meaning to the shell. ,That's why you must use the -i option to match the case-insensitive pattern. Grep is a case-sensitive command by default. However, there are a few things that you should follow while using the grep command in Linux − You can use the grep command to display the specific file's name that contains a particular pattern you are looking for. Unlike other operating systems, finding any file in Linux is simple because you can use the grep command to search any file. Linux contains various types of commands and utilities to simplify every task. It is considered one of the most useful commands on Unix / Linux-like systems for sysadmins and developers. This command filters and searches for a particular pattern of characters and displays them as output. Grep (global regular expression print) command matches and searches the specific pattern in the regular expressions.
