15

I want to pipe stdout to multiple files, but keep stdout itself quiet. tee is close but it prints to both the files and stdout

$ echo 'hello world' | tee aa bb cc
hello world

This works but I would prefer something simpler if possible

$ echo 'hello world' | tee aa bb cc >/dev/null
Zombo
  • 1
  • 62
  • 391
  • 407
  • 3
    In `tee aa bb cc`, `tee` has to write 3 files, and you still have `bash` redirecting standard output to a file. In `tee aa bb > cc`, you have the bash redirect, but `tee` only needs to write to 2 files. I'd say the 2nd is more efficient, but only in the strictest sense; you'll never notice the difference. – chepner Mar 07 '13 at 13:39

2 Answers2

19

You can simply use:

echo 'hello world' | tee aa bb > cc 
anishsane
  • 20,270
  • 5
  • 40
  • 73
7

You can also close tee stdout output by writing to /dev/full

echo 'hello world' | tee aa bb cc >/dev/full

or by closing stdout.

echo 'hello world' | tee aa bb cc >&-

Be however aware that you will get either tee: standard output: No space left on device or tee: standard output: Bad file descriptor warnings.

Jirka
  • 365
  • 2
  • 8
  • 2
    `/dev/null`, not `/dev/full` – anishsane Jan 26 '16 at 10:59
  • 4
    Not. it's indeed `/dev/full` so that the pipe is closed. With `/dev/null`, `tee` will still continue to write, even if there is no space left for files `aa`, `bb` and `cc`. – Jirka Jan 31 '19 at 21:08
  • 1
    Won't this make `tee` fail immediately since it will get an error writing to stdout? The rest of the output of the pipe won't be written to the named files. – Barmar Jun 26 '23 at 15:02