Pipe to multiple files, but not stdout
Asked Answered
A

2

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
Anderegg answered 7/3, 2013 at 7:15 Comment(1)
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.Libbie
H
19

You can simply use:

echo 'hello world' | tee aa bb > cc 
Hydro answered 7/3, 2013 at 7:22 Comment(0)
H
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.

Horseshit answered 20/11, 2015 at 2:3 Comment(3)
/dev/null, not /dev/fullHydro
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.Horseshit
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.Magistery

© 2022 - 2024 — McMap. All rights reserved.