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 grep command if you specifically need GNU grep options. These are optional and not required for the steps below.

Step-by-Step

  1. 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.

  2. Navigate to the folder you want to search. Use the cd command followed by the folder path. For example, to search your Documents folder, type cd %USERPROFILE%\Documents and press Enter. If the path contains spaces, wrap it in double quotes, like cd "C:\My Folder". You can also open File Explorer, go to the folder, click the address bar, type cmd, and press Enter to open a command window already in that folder.

  3. Run a basic search in a single file. Type findstr "error" logfile.txt and press Enter. This prints every line in logfile.txt that contains the word error. Replace logfile.txt with your file name. The search is case-sensitive by default, so Error and error are different. Add /i to ignore case: findstr /i "error" logfile.txt.

  4. Search all files in the current folder. Use a wildcard: findstr /i "error" *.txt. This searches every .txt file 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.

  5. Search subfolders recursively. Add /s to include all subdirectories: findstr /s /i "error" *.txt. This is the closest equivalent to grep -r. The output will show the file name before each matching line, which helps when you are searching many files.

  6. Show line numbers. Add /n to 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.

  7. 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.

  8. Use regular expressions. findstr supports a limited set of regular expression characters when you add /r. For example, findstr /r "^Error" logfile.txt matches 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's Select-String or install a real grep.

  9. Filter the output of another command. You can pipe output into findstr just 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.

  10. Save results to a file. Redirect the output with >: findstr /s /i "error" *.txt > results.txt. This writes all matches to results.txt in the current folder. Use >> to append instead of overwrite.

  11. Check the exit code when scripting. After a search, the special variable %ERRORLEVEL% in Command Prompt (or $LASTEXITCODE in 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.

  12. 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, findstr treats each word as a separate search term and may return unexpected results.
  • Assuming case-insensitivity. findstr is 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. findstr supports only a small subset. Complex patterns will not work; use PowerShell or real grep instead.
  • Running from the wrong directory. If you do not cd into the target folder first, findstr searches only the current working directory, which is often your user folder.
  • Typing grep in Command Prompt. It will say the command is not recognized. Use findstr or 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 /n for 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 /l switch to treat the search as literal text.
  • In PowerShell, Select-String is 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 findstr or 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 /i in case the case differs.
  • "File not found" error. The path or file name is wrong. Use dir to 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 .txt even 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.