tail — Output the last lines of a file across all 5 shells
Equivalents in every shell
Worked examples
Follow a growing log file
Bash
tail -f app.logPowerShell
Get-Content app.log -Wait -Tail 10Show last 50 lines
Bash
tail -n 50 app.logPowerShell
Get-Content app.log -Tail 50Tail multiple files
Bash
tail -f *.logPowerShell
Get-ChildItem *.log | ForEach-Object { Get-Content $_ -Tail 5; Write-Host '--' }Gotchas
- `Get-Content -Wait` polls; on very high-throughput files it can drop lines compared to GNU `tail -f` (which uses inotify on Linux).
- cmd alone has no tail equivalent — you must shell out to PowerShell, install GNU coreutils, or use WSL.
- `tail -F` (capital) on GNU tail re-opens the file if rotated; `-Wait` in PowerShell does not handle log rotation gracefully.
WSL & PowerShell Core notes
pwsh`Get-Content -Tail N` works on every pwsh platform. For very large files (multi-GB log files) it streams from the end, so it remains fast — unlike `Get-Content file | Select-Object -Last N` which reads the whole file first. Use `-Tail` for any "last N lines" job on a sizable log.
WSLTailing a file on `/mnt/c/...` from WSL works but is materially slower than tailing a file in the WSL filesystem (`~/`) because DrvFs polls Windows file changes rather than relying on inotify — `tail -f /mnt/c/logs/app.log` updates with a 1–2s lag and can miss lines on bursty writes. For low-latency log following, either keep the log inside `~/` or run `Get-Content -Wait` from Windows-side PowerShell.
Common tasks using tail
- Attach to the output of a running process
Read the stdout/stderr of an already-running process you did not launch — for debugging daemons, observing what a frozen-looking job is doing, and tailing logs that weren't redirected at start.
- Count lines in a file
Get the line count of one or more files, recursively or in a single command.
- Pick a random line from a file
Select one random line from a file — useful for fortune-style picks, A/B bucketing, and test sampling.
- Redirect stderr to a file
Capture only error output from a command, optionally merged with stdout, into a file.
- Tail a log file in real time
Follow a growing log file as new lines are appended (`tail -f`-style).
- Watch a file for changes
React when a file is modified — for tail-style log viewing, hot-reload tooling, or "wait until this completes" automation.