•Arnošt Havelka
Findstr Command
Advanced text search with regular expressions.
Start Interactive Lessonfindstr is the big brother of find. It supports regular expressions (regex), searches recursively across directories, and offers more powerful filtering options. It is comparable to grep in Linux.
Try the command
Search recursively for a pattern!
Build the command
findstr
/nPrints the line number before each line that matches.
Terminal
C:\Users\User>findstr /s "error" *.txt
Common Options
- /S: Recursively searches subdirectories. This is a huge advantage over
find. - /R: Uses regular expressions. This allows for complex pattern matching (e.g.,
^for start of line,$for end of line). - /B: Matches pattern if at the beginning of a line.
- /E: Matches pattern if at the end of a line.
Real-World Examples
1. Finding files containing "TODO" in an entire project
Search every .js file in the current folder and subfolders.
Command Prompt
C:\Users\User>findstr /s /n "TODO" *.js
2. Using Regex to find numbers
Find lines that start with a number.
Command Prompt
C:\Users\User>findstr /r "^[0-9]" data.txt
3. Searching for multiple strings
Find lines containing either "Error" or "Warning".
Command Prompt
C:\Users\User>findstr "Error Warning" app.log
Knowledge Check
1 / 3Which flag enables recursive search in subdirectories?
References
These documentation links provide authoritative details for the commands used in this article.