tee command (Linux / bash / sh / zsh)
What it does
Copy standard input to standard output and one or more files. When people search for the tee command linux output file, they usually want tee's everyday flags, safe examples, and how it differs from related tools. Below you'll find syntax, options, and copyable examples for Bash/sh/zsh.
Copy standard input to standard output and one or more files.
Syntax
tee [OPTION]... [FILE]...
Common options
| Flag / option | Meaning |
|---|---|
| -a | Append rather than overwrite. |
| -i | Ignore interrupt signals. |
| -p | Diagnose errors writing to pipes. |
| --output-error=MODE | Control write-error handling. |
Practical examples
Save and display
make | tee build.log
Shows build output while recording it.
Append log
echo 'deployed' | tee -a deploy.log
Adds a line and echoes it.
Write privileged file
echo 'value=1' | sudo tee /etc/app.conf >/dev/null
Lets tee perform the elevated write.
Common mistakes
- Forgetting that tee overwrites files unless `-a` is used.
- Using `sudo echo ... > file`; redirection is not elevated.
Related commands
- echoWrite arguments and shell-expanded values to standard output.
- catConcatenate files and write their contents to standard output.
- xargsBuild and run command invocations from standard input.
- grepSearch text for lines matching a pattern.
- Where-ObjectFilter pipeline objects by property values or a script block predicate.
- Get-ContentRead file content or provider data as a stream of objects.
- echoDisplay text or control command echoing in a batch script.
- tailPrint the end of input and optionally follow appended data.
FAQ
What does tee do in Linux?
Copy standard input to standard output and one or more files.
How do I use tee from the terminal?
Start with `tee [OPTION]... [FILE]...`, then choose only the options needed for the task.
What is a practical tee example?
Try `make | tee build.log` — Shows build output while recording it.
Can I use tee in a shell script?
Yes. tee works in Bash, sh, and Zsh, but scripts should handle quoting, errors, and command output explicitly.
Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.