Skip to content
shellmap

teeRead stdin and write to both stdout and one or more files at once across all 5 shells

Equivalents in every shell

Bashunix
command | tee output.txt
Zshunix
command | tee output.txt
Fishunix
command | tee output.txt

Same external `tee` binary. Fish has no built-in `tee` of its own.

PowerShellwindows
command | Tee-Object -FilePath output.txt

Aliased as `tee`. Like its Unix cousin, it returns the pipeline and writes to the file.

cmd.exewindows
(command) > output.txt & type output.txt

No 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

Bash
make 2>&1 | tee build.log
Fish
make 2>&1 | tee build.log
PowerShell
make 2>&1 | Tee-Object -FilePath build.log

Append to a log instead of overwriting

Bash
echo "deploy at $(date)" | tee -a deploys.log
PowerShell
"deploy at $(Get-Date)" | Tee-Object -FilePath deploys.log -Append

Write to a root-owned file from an unprivileged shell

Bash
echo "127.0.0.1 myhost" | sudo tee -a /etc/hosts
Fish
echo "127.0.0.1 myhost" | sudo tee -a /etc/hosts

Gotchas

  • `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

pwshPowerShell Core ships `Tee-Object` and the `tee` alias on every platform. On Linux/macOS pwsh the alias does NOT shadow the system `/usr/bin/tee` — script files invoked from `bash` or via `#!/usr/bin/env tee` still use the Unix binary.
WSLInside WSL `tee` is the GNU coreutils binary. Writing through `tee` to `/mnt/c/...` works but goes via DrvFs (slower than native paths) and triggers Windows Defender real-time scans on each write.

Common tasks using tee

Related commands