Linux - What is the use of ‘grep’ command? Provide an example

What is the use of ‘grep’ command? Provide an example

Grep stands for regular expression. ‘grep’ command is used to find the patterns in a text file provided by the user. It returns true if the pattern is found in the file, otherwise false.

Examples:

grep Lin file1 file2 file3
searches the files file1, file2, file3 for the lines which contains the string Lin.

grep ‘Linux learning is great ’ file1 file2 file3
searches the files file1, file2, file3 for the lines which contains the string ‘Linux learning is great’.

grep -c Linux operatinsystems
displays only the number of times that the pattern is matched in the file but not the lines.

grep -r 'Linus Torvalds' *
searches for the files in current and all the sub directories for the pattern (Linus Torvalds).
Linux - Difference between cat and more command
Difference between cat and more command - The file contents are displayed by ‘cat’ command.........
Linux - What is ‘du’ command? What is its use?
What is ‘du’ command? What is its use? - The du (disk usage) command is used to report the size of directory trees......
Linux - Explain the various prompts that are available in a UNIX system
Explain the various prompts that are available in a UNIX system - UNIX supports 4 prompts - PS1: default prompt.......
Post your comment