Home·Terminal commands

tee

Text processing

Usage

[cmd] | tee [file]

Copies its input into a file and on to the screen at once; it is how you write to a root-owned file, because in sudo cmd > file the redirect is opened by your own shell.

Common flags

FlagMeaning
-aAppend to the file instead of overwriting it
-iIgnore Ctrl-C while the pipe runs
-pGNU: report errors when writing to a pipe

Examples

make 2>&1 | tee build.log

Watch the build and keep a copy.

echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf

Appends to a root-owned file, which > cannot do.

curl -s api | tee raw.json | jq .name

Keeps the raw body and reads one field.

These were built to be piped together. Three joined commands are usually shorter than one that does everything.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does tee do?

Copies its input into a file and on to the screen at once; it is how you write to a root-owned file, because in sudo cmd > file the redirect is opened by your own shell.

Q. How do I type it?

[cmd] | tee [file] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

3 are listed here; the full set is in man tee. This command sits under Text processing.

Related commands

man page: man tee