How To Use The Findstr Command In Windows (2027)
Findstr searches for text inside files from Command Prompt and prints every line that matches.
The simplest form is findstr "text" filename.txt, and a handful of switches handle case, subfolders and line numbers.
This guide follows Microsoft’s findstr reference, so every switch and example below is documented.
Table of Contents
- Findstr quick answers
- Open Command Prompt in the right folder
- The findstr syntax
- Findstr switches at a glance
- Switches that take a value
- Search for a phrase, not separate words
- Search every file in a folder and its subfolders
- Regular expression characters
- Match whole words
- Use a file of search terms
- Find lines that start with a word
- Literal text or regular expression
- Show lines that do not match
- Search several folders at once
- Mistakes that break a findstr command
- Save the results to a file
- The PowerShell alternative
- Related guides
- Official sources
- More Windows guides
Findstr quick answers
| I want to | Type this |
|---|---|
| Find a word in one file | findstr Windows proposal.txt |
| Find an exact phrase | findstr /c:"hello there" x.y |
| Ignore upper and lower case | findstr /i windows proposal.txt |
| Search all subfolders | findstr /s /i Windows *.* |
| Show line numbers | findstr /n Windows proposal.txt |
| List only file names | findstr /s /i /m computer *.* |
The file names here are Microsoft’s samples, so replace them with your own.
Open Command Prompt in the right folder
- Press the Windows key and type cmd, then open Command Prompt.
- Use
cdto move to the folder that holds your files, for examplecd C:\Users\YourName\Documents. - Type your findstr command and press Enter.
Findstr searches the current directory unless you give a path.
The findstr syntax
Microsoft gives the syntax as findstr [/b] [/e] [/l | /r] [/s] [/i] [/x] [/v] [/n] [/m] [/o] [/p] [/f:.
Microsoft states that all options must come before the search strings and the file names.
Both the search text and at least one file name are required.
Findstr switches at a glance
| Switch | What it does |
|---|---|
/b | Matches the pattern only at the beginning of a line. |
/e | Matches the pattern only at the end of a line. |
/l | Treats search strings literally. |
/r | Treats search strings as regular expressions, and this is the default. |
/s | Searches the current directory and all subdirectories. |
/i | Ignores the case of the characters. |
/x | Prints only lines that match exactly. |
/v | Prints only lines that do not contain a match. |
/n | Prints the line number of each matching line. |
/m | Prints only the file name when a file contains a match. |
/o | Prints the character offset before each matching line. |
/p | Skips files with non-printable characters. |
Switches that take a value
| Switch | What it does |
|---|---|
/c: | Uses the text as a literal search string, including spaces. |
/g: | Gets the search strings from a file. |
/f: | Gets the list of files to search from a file. |
/d: | Searches a list of directories separated with semicolons, such as dir1;dir2;dir3. |
/a: | Sets the color with two hexadecimal digits. |
/off[line] | Does not skip files that have the offline attribute set. |
Search for a phrase, not separate words
Microsoft says spaces separate multiple search strings unless the argument is prefixed with /c.
So findstr hello there x.y looks for either word, while findstr /c:"hello there" x.y looks for the whole phrase.
Search every file in a folder and its subfolders
Add /s to search the current directory and every folder below it.
Microsoft’s example findstr /s /i Windows *.* searches every file for Windows and ignores case.
Add /m when you only want to know which files contain the text.
Regular expression characters
| Character | Meaning |
|---|---|
. | Any one character. |
* | Zero or more occurrences of the previous character or class. |
^ | The beginning of the line. |
$ | The end of the line. |
[class] | Any one character in the set. |
[^class] | Any one character not in the set. |
[x-y] | Any character in the range. |
\x | A literal use of a metacharacter. |
\ | The beginning of a word. |
string\> | The end of a word. |
Microsoft notes that the special characters work best in combination, and .* matches any string of characters.
Match whole words
Microsoft's example findstr /s /i /m \ lists every file that contains the word computer, whatever its case.
Changing it to \
Use a file of search terms
To search for several strings, put each one on its own line in a text file.
Then run Microsoft's example findstr /g:stringlist.txt /f:filelist.txt > results.out to read the terms from one file, the files from another, and save the output to results.out.
Find lines that start with a word
Microsoft shows findstr /b /n /r /c:^ *FOR *.bas for lines that begin with FOR, optionally after spaces, with their line numbers.
Literal text or regular expression
Findstr treats your search text as a regular expression by default, so a dot matches any character.
Add /l to search for the characters exactly as typed, which is safer when your text contains symbols.
Add /r only when you want pattern matching, since it is already the default.
Show lines that do not match
Use /v to print only the lines that do not contain a match.
Use /x to print only lines that match the search text exactly.
Use /b or /e to anchor the match to the start or end of a line.
Search several folders at once
The /d switch takes a list of directories separated with semicolons.
For example, findstr /d:C:\Logs;C:\Reports error *.txt would search the two folders for the word error, and the folder names here are placeholders.
Mistakes that break a findstr command
- Putting a switch after the file name, because Microsoft says all options must precede the strings and file names.
- Searching a phrase without
/c:, so each word is treated as a separate search string. - Leaving out the file name, since at least one is required.
- Forgetting
/sand wondering why files in subfolders are missed. - Using
.in a pattern when you meant a literal period, which needs\.or the/lswitch.
Save the results to a file
Add > results.txt to the end of any findstr command to write the matching lines to a file instead of the screen, as Microsoft's > results.out example does.
This helps when a search across many folders prints more lines than the window can show.
Combine it with /m to save just the list of file names that contain your text.
- Run the search on screen first and confirm the matches look right.
- Press the Up arrow to recall the command.
- Add
> results.txtand press Enter. - Open results.txt from the same folder to read the output.
The PowerShell alternative
PowerShell has the Select-String cmdlet, which Microsoft documents as matching case-insensitively by default.
| Need | Select-String parameter |
|---|---|
| Case-sensitive match | -CaseSensitive |
| Literal text, not a regular expression | -SimpleMatch |
| Lines that do not match | -NotMatch |
| Lines around each match | -Context 2,3 |
| Only the first match per file | -List |
A basic example is Select-String -Path .\*.txt -Pattern 'Get-', which searches every .txt file in the current folder.
Related guides
For network searches see the Netstat guide, which pairs well with a findstr filter.
To copy the files you find, see the Robocopy guide, and for system file checks see how to run SFC and DISM.
Official sources
Every switch, example and metacharacter comes from Microsoft's findstr reference.
The PowerShell details come from Microsoft's Select-String reference.
More Windows guides
- How To Use The Reg Add Command In Windows (2027)
- How To Use The Mklink Command In Windows (2026)
- How To Use The Schtasks Command In Windows (2026)
- How To Use The Takeown Command In Windows (2027)
- How To Use The Driverquery Command In Windows (2026)
- How To Use The Icacls Command In Windows (2027)
See all: Windows 11 Guides