tee — Read stdin and write to both stdout and one or more files at once across all 5 shells
Equivalents in every shell
command | tee output.txtcommand | tee output.txtcommand | Tee-Object -FilePath output.txtAliased as `tee`. Like its Unix cousin, it returns the pipeline and writes to the file.
(command) > output.txt & type output.txtNo native `tee` in cmd.exe. The only built-in way is to run the command twice or post-process with `type`. Install Git Bash / WSL / GnuWin32 for real tee.
Worked examples
Capture build output to a log while still seeing it on screen
make 2>&1 | tee build.logmake 2>&1 | tee build.logmake 2>&1 | Tee-Object -FilePath build.logAppend to a log instead of overwriting
echo "deploy at $(date)" | tee -a deploys.log"deploy at $(Get-Date)" | Tee-Object -FilePath deploys.log -AppendWrite to a root-owned file from an unprivileged shell
echo "127.0.0.1 myhost" | sudo tee -a /etc/hostsecho "127.0.0.1 myhost" | sudo tee -a /etc/hostsGotchas
- `tee` only sees standard output. To capture stderr too, redirect it first: `command 2>&1 | tee log`.
- On Unix, the idiomatic way to write to a root-owned file as a non-root user is `command | sudo tee file` — `sudo command > file` would still open `file` as the current user.
- `Tee-Object` writes one file at a time; to fan out to several files, chain multiple `Tee-Object -FilePath` calls.
- cmd.exe has no real `tee`. Running the command twice double-executes side effects (network calls, build steps) — prefer PowerShell, Git Bash, or WSL.
- PowerShell `Tee-Object` writes UTF-16 LE by default in Windows PowerShell 5.1. Pass `-Encoding utf8` (or use pwsh 7+) for portable log files.
WSL & PowerShell Core notes
Common tasks using tee
- Append command output to a file
Add a command's output to the END of a file (creating it if missing) without erasing existing content — for incremental logs, config patches, and accumulators.
- Merge stderr into stdout
Combine a command's error stream with its normal output so a single pipe / file / variable captures BOTH — essential for log aggregation and CI capture.
- Suppress stderr from a command
Discard a command's error output (without affecting stdout or exit code) — for noisy tools whose warnings clutter scripts and CI logs.
- Tee command output to a file and stdout
Write a command's stdout to a file AND echo it to the terminal in one pass — for logged-but-watchable installer / build / CI runs.