Skip to content
shellmap

grepSearch file contents for a pattern across all 5 shells

Equivalents in every shell

Bashunix
grep -r "pattern" .
Zshunix
grep -r "pattern" .
Fishunix
grep -r "pattern" .
PowerShellwindows
Select-String -Pattern "pattern" -Path *.txt

Aliased as `sls`. Outputs match objects, not plain lines.

cmd.exewindows
findstr /S /I "pattern" *

`/S` recurses subdirectories, `/I` is case-insensitive.

Worked examples

Recursive case-insensitive search

Bash
grep -ri "todo" .
PowerShell
Get-ChildItem -Recurse | Select-String -Pattern "todo"
cmd.exe
findstr /S /I "todo" *

Show line numbers

Bash
grep -n "error" app.log
PowerShell
Select-String -Pattern "error" -Path app.log
cmd.exe
findstr /N "error" app.log

Invert match (lines NOT matching)

Bash
grep -v "DEBUG" app.log
PowerShell
Select-String -Pattern "DEBUG" -NotMatch -Path app.log
cmd.exe
findstr /V "DEBUG" app.log

Gotchas

  • `Select-String` emits objects with `.Line`, `.LineNumber`, `.Path` — pipe to `ForEach { $_.Line }` for plain output.
  • cmd `findstr` regex syntax is limited; no `\d`, no lookarounds. Use PowerShell or grep for real regex.
  • PowerShell 7+ also exposes `grep` via WSL or `Microsoft.PowerShell.TextUtility` — but `Select-String` is canonical.

WSL & PowerShell Core notes

pwsh`Select-String` is built into PowerShell Core (`pwsh`) on every platform — Windows, macOS, Linux — so scripts targeting pwsh 7+ can rely on it everywhere. The Unix `grep` binary is not shipped with Windows; install Git for Windows, MSYS2, or WSL to get it.
WSLWSL ships GNU `grep`. To search Windows files from WSL, `grep -r "pattern" /mnt/c/path` works but is much slower than grepping the Linux filesystem. For mixed projects, keep the working tree under `~` and use Windows interop (e.g. `code .`) to open it in Windows-side editors.

Related glossary

Common tasks using grep

Related commands