You can search for text in files using several command-line tools. Here are some common methods:
Using
grep:grep "search_term" filename.txtThis command searches for "search_term" in
filename.txtand displays the matching lines.Using
grepwith options:- Case-insensitive search:
grep -i "search_term" filename.txt - Show line numbers:
grep -n "search_term" filename.txt - Search recursively in directories:
grep -r "search_term" /path/to/directory
- Case-insensitive search:
Using
findwithgrep: To search for a term in multiple files:find /path/to/directory -type f -exec grep "search_term" {} +Using
nano(text editor):- Open the file:
nano filename.txt - Press
Ctrl + W, type the search term, and pressEnter.
- Open the file:
Using
less:- Open the file:
less filename.txt - Press
/, type the search term, and pressEnter.
- Open the file:
Choose the method that best fits your needs!
