Skip to content
shellmap

wcCount lines, words, or bytes across all 5 shells

Equivalents in every shell

Bashunix
wc -l file
Zshunix
wc -l file
Fishunix
wc -l file
PowerShellwindows
(Get-Content file).Count

Returns the line count. Use `Measure-Object -Line -Word -Character` for more.

cmd.exewindows
find /c /v "" file

`/c /v ""` counts lines NOT matching empty — i.e. all lines.

Worked examples

Count lines

Bash
wc -l file.txt
PowerShell
(Get-Content file.txt | Measure-Object -Line).Lines
cmd.exe
find /c /v "" file.txt

Count words

Bash
wc -w file.txt
PowerShell
(Get-Content file.txt | Measure-Object -Word).Words

Count files in a directory

Bash
ls -1 | wc -l
PowerShell
(Get-ChildItem).Count
cmd.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

Related commands