How to use grep command for file search in Linux OS

[425 views]




What is grep?

grep stands for Global regular expression print. It is the most powerful command-line search util for linux and other unix OS. You can use grep to search for different patterns in files in all the system.

Basic syntax for grep-

grep [options] pattern [file...] options - an optional flags list that control the behavior of the grep util command. pattern - the Regex pattern to search file - an optional list of files to search

Basic Usage of Grep (example):

grep "jackson" pom.xml

Grep will return every line that contains the exact text jackson in the file pom.xml

<groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId>

Some commonly used flags in grep:
-i :- It makes the grep command case insensitive
-v :- invert the match functionality of grep command
-n :- show line number inside file in which the match is found

                 






Comments










Search Anything:

Sponsored Deals ends in



Interesting Technical Quizzes:

Search Tags