Search for text in files on Linux - Here's how
This practical tip shows you how to search for text in files under Linux.
Use grep to search for text in files
Open the console with the key combination [Ctrl] + [Alt] + [T] or enter "Terminal" in the search bar and confirm.
- Type in "grep 'word' ./". With this command, Linux searches for all files in the current directory that contain the term "word". Don't be surprised if the search takes a while. Depending on the size of the directory, the search can take some time.
- If you want to include subdirectories, the parameter "-r" will help you. A search would look like "grep -r 'word' ./".
- Linux is currently looking for case-sensitive, meaning it is case-sensitive. To prevent this, add the parameter "-i" to the command.
- Use a regular expression, replace "grep" with "egrep".
- As output you will receive the file path to the files that contain the search pattern.
If you want to continue working with the files afterwards, you will find another practical tip on how to combine files under Linux.