In Linux grep stands for “global regular expression print”. The grep command used in searching and matching text files contained in the regular expressions.
The syntax is:
# grep pattern filename
| SNo | Example | Explanation |
|---|---|---|
| 1 |
# grep apple filename |
The word apple will get extract from the filename |
| 2 |
# grep -i apple filename |
‘-i’ is a ignore case sensitive |
| 3 |
# ls -l | grep filename |
List the files and in the listed files extract the filename |
| 4 |
# ls -l | grep d |
Lists all the directories including files starting with d |
| 5 | # ls -l | grep ^d |
In this we will get only directories starting character of ‘d’ |
| 6 |
# ls -l | grep ^- |
In this we will get only files |

Comments
Post a Comment