Grep Cheat Sheet
Grep Cheat Sheet
ux | by Cuncis | Medium
Search
Listen Share
grep is a powerful command-line utility in Linux and Unix operating systems that
allows you to search for specific patterns of text within one or more files. The name
"grep" stands for "global regular expression print".
Where:
[options] : optional arguments that modify the behavior of the grep command
https://medium.com/@cuncis/mastering-grep-command-your-complete-cheat-sheet-for-efficient-text-searching-in-linux-b569a573432b 1/11
1/9/24, 7:13 AM Mastering grep Command: Your Complete Cheat Sheet for Efficient Text Searching in Linux | by Cuncis | Medium
[file ...] : the file or files you want to search for the pattern
The grep command works by reading the contents of the specified file or files and
searching for lines that match the specified pattern. It then prints out the lines that
match the pattern to the standard output (usually the terminal window).
Basic Usage:
grep pattern file : Search for pattern in file
grep pattern file1 file2 file3 : Search for pattern in multiple files
grep pattern *.txt : Search for pattern in all files with the .txt extension
Options:
-i : Ignore case (case-insensitive search)
https://medium.com/@cuncis/mastering-grep-command-your-complete-cheat-sheet-for-efficient-text-searching-in-linux-b569a573432b 2/11