If you’re switching from Linux to Windows and missing the comfort of grep or find, don’t worry — Windows has tools for that too. While PowerShell is your go-to command-line solution, there are also classic cmd commands and third-party utilities to get the job done.
This post walks you through how to search for specific text in files and folders on Windows, with examples for PowerShell, Command Prompt, and other tools. Whether you’re a developer or just managing a lot of files, these tips will save you time.
PowerShell: The Modern Way
PowerShell is the most powerful built-in tool on Windows for searching text in files. Here’s how to use it.
Basic Search:
Get-ChildItem -Recurse -File | Select-String 'class="itemExtraFields"' | Select-Object Path, LineNumber, Line
This command will:
- Search all files in the current folder and subfolders.
- Look for the string class=”itemExtraFields”.
- Show you the file path, line number, and the actual line of text.
Filter by File Type (e.g., if you want to search only .html or .php files):
Get-ChildItem -Recurse -Include *.html,*.php -File | Select-String 'class="itemExtraFields"'
Save Results to a File:
... | Out-File results.txt
Command Prompt (cmd.exe)
If you’re more old-school or just don’t like PowerShell:
findstr /S /I /M "itemExtraFields" *.*
Explanation:
- /S – search subfolders
- /I – ignore case
- /M – show only the filenames with matches
To show matching lines as well:
findstr /S /I "itemExtraFields" *.*
Limiting to .html files:
findstr /S /I "itemExtraFields" *.html
Just a note, findstr doesn’t handle special characters as well as PowerShell (especially quotes or regex), but it’s fast and lightweight.
Notepad++: GUI Way to Search in Files
For those who prefer a GUI:
- Open Notepad++
- Press Ctrl+Shift+F to open Find in Files
- Enter your search term: class=”itemExtraFields”
- Choose the directory and file types to search
- Click Find All
This is great for quickly previewing matches and jumping between files.
Git Bash or WSL: Bring Linux Tools to Windows
If you’ve installed Git for Windows, you get grep!
grep -r 'class="itemExtraFields"' .
And if you use WSL (Windows Subsystem for Linux):
find . -type f -exec grep -H 'class="itemExtraFields"' {} \;
Perfect for those who miss their native Unix tools.