Windows does not have a built-in command called grep. The equivalent is findstr, a command-line tool included in every modern version of Windows. You can use it to search for text inside files, filter command output, and search recursively through folders. If you prefer the exact grep syntax, you can install a port like Git Bash or Windows Subsystem for Linux (WSL), but for most everyday searches findstr is already on your PC and needs nothing extra.
What You'll Need
- A Windows PC (Windows 10 or 11 works the same for these steps).
- Access to Command Prompt or PowerShell. Both are built in; no download is required.
- The folder path or file name you want to search. You can type it manually or copy it from File Explorer.
- Optional: Git for Windows, WSL, or another package that provides a real
grepcommand if you specifically need GNU grep options. These are optional and not required for the steps below.
Step-by-Step
Open a command window. Press the Windows key, type
cmd, and press Enter to open Command Prompt. Alternatively, open PowerShell the same way. The commands in this guide work in both unless noted. Menu labels and window titles can differ slightly by Windows version and region.Navigate to the folder you want to search. Use the
cdcommand followed by the folder path. For example, to search your Documents folder, typecd %USERPROFILE%\Documentsand press Enter. If the path contains spaces, wrap it in double quotes, likecd "C:\My Folder". You can also open File Explorer, go to the folder, click the address bar, typecmd, and press Enter to open a command window already in that folder.Run a basic search in a single file. Type
findstr "error" logfile.txtand press Enter. This prints every line inlogfile.txtthat contains the word error. Replacelogfile.txtwith your file name. The search is case-sensitive by default, soErroranderrorare different. Add/ito ignore case:findstr /i "error" logfile.txt.Search all files in the current folder. Use a wildcard:
findstr /i "error" *.txt. This searches every.txtfile in the folder. To search every file regardless of extension, use*.*. Be aware that binary files may produce odd output; limit the wildcard to the file types you care about.Search subfolders recursively. Add
/sto include all subdirectories:findstr /s /i "error" *.txt. This is the closest equivalent togrep -r. The output will show the file name before each matching line, which helps when you are searching many files.Show line numbers. Add
/nto print the line number at the start of each match:findstr /n /i "error" logfile.txt. This is useful for editing or referring to a specific line later.Search for multiple words. Separate search terms with spaces inside the quotes:
findstr /i "error warning critical" logfile.txt. This matches lines containing any of those words. To match a whole phrase, put the phrase in quotes:findstr /i "connection refused" logfile.txt.Use regular expressions.
findstrsupports a limited set of regular expression characters when you add/r. For example,findstr /r "^Error" logfile.txtmatches lines that start with Error. The.and*characters work, but advanced regex features like lookahead are not supported. If you need full regex, use PowerShell'sSelect-Stringor install a real grep.Filter the output of another command. You can pipe output into
findstrjust like grep. For example,ipconfig | findstr /i "IPv4"shows only the lines containing IPv4. This works with any command that writes text to the console.Save results to a file. Redirect the output with
>:findstr /s /i "error" *.txt > results.txt. This writes all matches toresults.txtin the current folder. Use>>to append instead of overwrite.Check the exit code when scripting. After a search, the special variable
%ERRORLEVEL%in Command Prompt (or$LASTEXITCODEin PowerShell) is 0 if matches were found, 1 if no matches were found, and 2 if there was an error such as a missing file. This lets you branch in batch files.If you need real grep syntax, install it. The official way is to install Git for Windows (which includes Git Bash) or enable WSL through Windows Features. Both are free and official. Once installed, you can run
grep -r "error" .inside Git Bash or a WSL terminal. Do not download random grep binaries from unofficial sites.
Common Mistakes
- Forgetting the quotes around search terms that contain spaces. Without quotes,
findstrtreats each word as a separate search term and may return unexpected results. - Assuming case-insensitivity.
findstris case-sensitive unless you add/i. Many people expect grep-like default behavior and miss matches. - Using
*.*on a large folder tree. This can be slow and may include binary files that produce garbled output. Narrow the wildcard to the extensions you need. - Expecting full regular expression support.
findstrsupports only a small subset. Complex patterns will not work; use PowerShell or real grep instead. - Running from the wrong directory. If you do not
cdinto the target folder first,findstrsearches only the current working directory, which is often your user folder. - Typing
grepin Command Prompt. It will say the command is not recognized. Usefindstror open a Git Bash/WSL terminal.
Tips
- Use
findstr /?to see the full list of options directly in the command window. The help text is the most reliable reference for your Windows version. - Combine
/s,/i, and/nfor a recursive, case-insensitive search with line numbers:findstr /s /i /n "error" *.log. - To search for a literal string that includes special characters, escape them or use the
/lswitch to treat the search as literal text. - In PowerShell,
Select-Stringis a more powerful alternative that supports full regular expressions and object output. Example:Get-ChildItem -Recurse *.txt | Select-String "error". - If you often need grep, install Git for Windows once and use Git Bash for all your text searching. It provides the familiar grep, egrep, and fgrep commands.
Troubleshooting
- "'grep' is not recognized as an internal or external command." You are in Command Prompt or PowerShell, which do not include grep. Use
findstror open Git Bash/WSL. - No output at all. Check that you are in the correct folder, that the file name or wildcard matches existing files, and that your search term is spelled correctly. Try adding
/iin case the case differs. - "File not found" error. The path or file name is wrong. Use
dirto list files in the current folder and confirm the exact name. Remember that Windows hides file extensions by default in File Explorer, so the actual name may include.txteven if you do not see it. - Access denied. You are trying to search a protected system folder. Run the command window as administrator only if you understand the risks, or search a user folder instead.
- Garbled output from binary files. Limit your wildcard to text extensions like
*.txt,*.log, or*.csv. - Search is very slow. Recursive searches over large drives take time. Narrow the starting folder or the file pattern. Avoid searching the entire C: drive unless necessary.
Frequently Asked Questions
Is there a built-in grep in Windows?
No. Windows includes findstr, which covers most basic grep use cases. For full grep, install Git for Windows or enable WSL.
What is the difference between findstr and grep?
findstr is Microsoft's tool with a smaller set of options and limited regular expression support. grep is the Unix tool with more features and broader regex support. The basic search syntax is similar.
Can I use grep in PowerShell?
Not directly unless you have installed a grep binary. PowerShell has its own Select-String cmdlet, which is more powerful than findstr and supports full regular expressions.
How do I search all files in a folder and its subfolders?
Use findstr /s "term" *.* from the folder you want to search. Add /i for case-insensitive matching and /n for line numbers.
Does findstr support regular expressions?
It supports a limited subset when you use the /r switch. Features like lookahead and backreferences are not available. For complex patterns, use PowerShell's Select-String or real grep.
Can I search inside PDF or Word files with findstr?
No. findstr works on plain text. PDF and Word files are binary formats, so you need to extract the text first or use a dedicated search tool.