Alternative to the tee command without STDOUT
Another option that avoids piping the stuff back and then to /dev/zero
is
sudo command | sudo dd of=FILENAME
The dd
solution still prints junk to stderr:
$ ls | sudo dd of=FILENAME
0+1 records in
0+1 records out
459 bytes (459 B) copied, 8.2492e-05 s, 5.6 MB/s
That can be avoided using the status
option:
command | sudo dd status=none of=FILENAME
Another interesting possibility (for Linux anyway):
command | sudo cp /dev/stdin FILENAME
To copy TTY input into a file, I often do this:
sudo cp /dev/tty FILENAME
It's too bad tee doesn't have an option to suppress stdout.
You could use a script. I.e. put something like this in i.e. $HOME/bin/stee
, 0tee
or similar:
#!/bin/bash
argv=
while [[ "$1" =~ ^- ]]; do
argv+=" $1"
shift
done
sudo tee $argv "$1" > /dev/null
#!/bin/bash
sudo tee "$@" > /dev/null
Make it executeable:
$ chmod 755 stee
Now do i.e.:
$ ls -la | stee -a /root/foo