Measure-Object
Count, sum, or average
Get-ChildItem -File | Measure-Object -Property Length -Sum
- Works on
- WindowsLinuxmacOS
- PowerShell
- 5.1 and later
- Reference
- Microsoft Learn: Measure-Object
Without parameters it counts. With -Property Length -Sum it adds file sizes. Also supports -Average, -Minimum, -Maximum, and -Line / -Word / -Character for text.
Try this
Get-Content -Path .\notes.txt | Measure-Object -Line -Word
Coming from another shell
| Shell | What you might type |
|---|---|
| bash / zsh | wc -l notes.txt |
More in From bash and From cmd.