Hide output of command while using cat and tee

catio-redirectiontee

I have a text file that contains some IPs. I want to copy the contents of this text file into /etc/ansible/hosts without showing the output on the terminal (as shown in example 2).

Note: root user is disabled.

If I use the following:

  1. sudo cat myfile.txt >> /etc/ansible/host

It will not work, since sudo cat didn't affect redirections (expected).

  1. cat myfile.txt | sudo tee --append /etc/ansible/hosts

It will show the output in the terminal then copy them to /etc/ansible/hosts
A.A.A.A
B.B.B.B
C.C.C.C

  1. Adding /dev/null will interrupt the result (nothing will be copied to /etc/ansible/hosts).

Best Answer

sudo tee -a /etc/ansible/hosts <myfile.txt >/dev/null

Or, if you want to use cat:

cat myfile.txt | sudo tee -a /etc/ansible/hosts >/dev/null

Either of these should work. It is unclear how you "added" /dev/null when you tried, but this redirects the standard output of tee to /dev/null.

Related Question