•Arnošt Havelka
Findstr Command
Advanced text search with regular expressions.
Start Interactive LessonFindstr Command
findstr 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.
Usage:findstr
[/options]
"pattern"
[filename]
/s
Searches for matching files in the current directory and all subdirectories.
/i
Specifies that the search is not to be case-sensitive.
/r
Uses search strings as regular expressions.
/n
Prints the line number before each line that matches.
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?