Skip to content
shellmap

get-contentPowerShell's file-read cmdlet — the cat / tail equivalent across all 5 shells

Equivalents in every shell

Bashunix
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.

Zshunix
cat file.txt

Same `/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).

Fishunix
cat file.txt

Same 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.

PowerShellwindows
Get-Content file.txt

PowerShell-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`.

cmd.exewindows
type file.txt

Built-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

Bash
cat file.txt
PowerShell
Get-Content file.txt -Raw
cmd.exe
type file.txt

Follow a log file as it grows (tail -f)

Bash
tail -f /var/log/syslog
PowerShell
Get-Content /var/log/app.log -Tail 0 -Wait

Read the last 20 lines of a file

Bash
tail -n 20 app.log
PowerShell
Get-Content app.log -Tail 20
cmd.exe
powershell -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.

WSL & PowerShell Core notes

pwsh`Get-Content` behaves identically on Windows, Linux, and macOS pwsh — but the `cat` and `type` aliases collide with Unix binaries on Linux/macOS, where pwsh REMOVES those aliases so the real binaries resolve first. Scripts targeting both Unix and Windows pwsh should always spell the full cmdlet name `Get-Content`.
WSLReading `/mnt/c/...` paths from a WSL shell goes through the Plan-9-style 9P drvfs adapter — significantly slower than reading native `~/`. For large logs (>100 MB) the right pattern is to `cp /mnt/c/path /tmp/path` first then read, or read from the Windows side with `Get-Content` directly without crossing into WSL.

Common tasks using get-content

Related commands