Lesson 3 of 35
Lesson Progress: 0%
The grep command searches for patterns inside files. You give it a pattern and one or more files, and it prints every line that matches. Unlike find, which searches for filenames,grep searches file contents. Use grep when you need to find lines of text that match a specific word, phrase, or pattern.
grep "hello" file.txt prints every line infile.txt that contains hello.grep is the standard tool for searching file contents in Linux.grep -i "hello" file.txt performs a case-insensitive search.-i flag makes grep ignore uppercase and lowercase differences.hello, Hello, orHELLO will all match.grep -r "hello" . searches recursively through all files in the current directory.-r flag tells grep to descend into subdirectories.grep -v "hello" file.txt prints lines that do NOT match the pattern.-v flag inverts the match.grep options like-i and -r.grep -c "hello" file.txt prints only the count of matching lines.-c flag stands for "count".grep -n "hello" file.txt shows matching lines with their line numbers.-n flag prefixes each match with its line number.-n with other flags like -iand -r.Test Incomplete
~$ grep "hello" file.txt~$ grep -i "hello" file.txt~$ grep -r "hello" .~$ grep -v "hello" file.txt~$ grep -c "hello" file.txt~$ grep -n "hello" file.txt