get-content — PowerShell's file-read cmdlet — the cat / tail equivalent across all 5 shells
Equivalents in every shell
cat file.txt`cat` writes the entire file to stdout. Companion tools handle partial / follow access: `head -n N`, `tail -n N`, `tail -f`. `cat` streams cleanly — files larger than RAM transit through a small buffer without bloating memory.
cat file.txtSame `/bin/cat`. macOS ships it in `/usr/bin/`. There is no zsh-specific reading builtin; the `<<<` here-string and `read` builtin handle different read patterns (single-line, stdin into a variable).
cat file.txtSame external `cat`. Fish has the `string` family for line-oriented work but no built-in file reader — `cat`, `head`, `tail` remain the idiom. `read -z` reads stdin null-terminated; `read --line` reads one line into a variable.
Get-Content file.txtPowerShell-native cmdlet (aliases `gc`, `cat`, `type`). Returns each LINE as a separate object — `(Get-Content file.txt).Count` is the line count. `-Raw` reads the whole file as ONE string (much faster for downstream regex). `-Tail N` is `tail -n N`; `-Wait` is `tail -f`.
type file.txtBuilt-in. `type file.txt` writes the whole file to stdout. No native `tail -f` — shell out to PowerShell `Get-Content -Wait`. cmd has no streaming text-encoding conversion.
Worked examples
Read an entire file
cat file.txtGet-Content file.txt -Rawtype file.txtFollow a log file as it grows (tail -f)
tail -f /var/log/syslogGet-Content /var/log/app.log -Tail 0 -WaitRead the last 20 lines of a file
tail -n 20 app.logGet-Content app.log -Tail 20powershell -c "Get-Content app.log -Tail 20"Gotchas
- `Get-Content` returns ONE STRING PER LINE by default — for a one-million-line file that's a million-element array, dramatically slower and memory-hungrier than Unix `cat`. Use `-Raw` for a single big string, or `-ReadCount N` to batch into N-line chunks for streaming downstream cmdlets.
- The default ENCODING differs between PowerShell versions. PS 5.1 (Windows-builtin) uses `Default` (system code page, often `windows-1252` on US systems); PS 7+ (`pwsh`) defaults to UTF-8 NO BOM. Scripts targeting both should specify `-Encoding UTF8` explicitly — silent corruption otherwise on non-ASCII text.
- `Get-Content -Wait` polls the file roughly every 1 second. It CANNOT detect `tail -F`-style file rotation (when the underlying file is replaced rather than appended) — most syslog setups rotate files, so a long-running `Get-Content -Wait` silently stops receiving new lines after the rotation. For rotation-aware follow use `wsl tail -F` on Windows or a wrapper that restarts on inode changes.
- PowerShell aliases `cat` and `type` to `Get-Content` — they don't accept Unix flags. `cat -n file` errors with `cannot find a positional parameter that accepts argument '-n'` because `Get-Content` has no `-n`. For line numbers: `Get-Content file | ForEach-Object -Begin { $i=1 } -Process { '{0,6}: {1}' -f $i++,$_ }`.
- Reading a non-existent path with `Get-Content` produces a NON-TERMINATING error (red text on console, execution continues), NOT an exception — code that relies on `try/catch` may silently continue past the failure. Use `-ErrorAction Stop` to promote to a terminating error, or `Test-Path` first.