wc — Count lines, words, or bytes across all 5 shells
Equivalents in every shell
Bashunix
wc -l fileZshunix
wc -l fileFishunix
wc -l filePowerShellwindows
(Get-Content file).CountReturns the line count. Use `Measure-Object -Line -Word -Character` for more.
Worked examples
Count lines
Bash
wc -l file.txtPowerShell
(Get-Content file.txt | Measure-Object -Line).Linescmd.exe
find /c /v "" file.txtCount words
Bash
wc -w file.txtPowerShell
(Get-Content file.txt | Measure-Object -Word).WordsCount files in a directory
Bash
ls -1 | wc -lPowerShell
(Get-ChildItem).Countcmd.exe
dir /b /a-d | find /c /v ""Gotchas
- GNU `wc -l` counts newline characters; a file without a trailing newline will be off-by-one vs. PowerShell `(Get-Content).Count` which counts lines.
- `Measure-Object -Word` splits on whitespace; differs from `wc -w` which has more nuanced UTF-8 word-boundary handling on some platforms.
- cmd `find /c /v ""` is an idiomatic but obscure line-count trick; document it in scripts.
WSL & PowerShell Core notes
pwsh`Measure-Object -Line` streams the file and is O(n) memory — same complexity as GNU `wc -l`. The convenience shortcut `(Get-Content file).Count` materialises every line into a `string[]` first, so memory usage grows proportionally to file size — fine for a 10MB log, ruinous for a 10GB one. For "is this file huge?" checks, prefer `(Get-Item file).Length` (byte size, O(1)) over a line count.
WSLGNU `wc -l` on a `/mnt/c/...` path is bandwidth-bound: counting lines in a 1GB Windows-side log takes seconds via DrvFs vs ~100ms on the same file copied to `~/`. No Windows or NTFS API exposes a fast precomputed line count, so `wc -l` can't shortcut — it must read every byte. As a faster proxy when only an order-of-magnitude estimate is needed, divide `(Get-Item file).Length` from Windows-side pwsh by the file's empirical average line length.
Common tasks using wc
- Count files changed since a commit
Get the number of distinct files that differ between a reference commit (a tag, SHA, or `origin/main`) and the working tree — for CI gates and PR-size summaries.
- Count files in a directory
Get a count of files (excluding directories) in a folder — at depth 1 or recursively, with hidden files included or excluded.
- Count lines in a file
Get the line count of one or more files, recursively or in a single command.
- Count the running processes
Report how many processes are alive — useful for load testing, capacity baselining, or detecting fork-bomb / runaway-parallelism conditions.
- Count words in a file
Count the number of whitespace-separated words in a file or piped text.
- Get a file size in bytes
Print the size of a file in bytes — for quotas, validation, and disk-usage scripts.