How to search for text inside files
Search file contents recursively with grep on Linux, findstr in CMD and Select-String in PowerShell — with context lines, exclusions and case-insensitive matching.
Beginner · about 5 min · Linux, Windows, macOS
Finding which config file sets a value, or which log line preceded a crash, is a content search rather than a filename search. Each platform has a native tool, and all three support recursion, case-insensitivity and context.
What this guide covers
- Linux: recursive search with line numbers
- Linux: context around each hit
- Linux: skip noisy directories
- Windows CMD: findstr
- PowerShell: Select-String returns objects
Common pitfalls covered
- Unquoted patterns get mangled by the shell — always quote.
- grep -F searches for a literal string; use it when your pattern contains dots, brackets or slashes.
- Binary files produce a 'binary file matches' line; add … to skip them.
Questions answered
- How do I search all files in a directory for a word?
- How do I search only certain file types?
- Is there anything faster than grep?
This is a limited preview. The full walkthrough, command syntax and copy-ready examples are available to signed-in users.