hide output of command while using cat and tee
Solution 1
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
.
Solution 2
Try to use bash with "-c" switch. For example:
sudo bash -c "cat /etc/hosts >> /etc/ansible/hosts" >> /dev/null
Related videos on Youtube
![Ahmad Abuhasna](https://i.stack.imgur.com/36Tx3.jpg?s=256&g=1)
Ahmad Abuhasna
“Every once in a while you need to challenge yourself and learn new things.” ― Amit Ray System Administrator at John Wiley and Sons ORACLE CERTIFIED ASSOCIATION (OCA)
Updated on September 18, 2022Comments
-
Ahmad Abuhasna almost 2 years
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:
sudo cat myfile.txt >> /etc/ansible/host
It will not work, since sudo cat didn't affect redirections (expected).
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
- Adding
/dev/null
will interrupt the result (nothing will be copied to/etc/ansible/hosts
).
-
Ahmad Abuhasna about 6 yearsThanks, I found the problem with my code, after reading cat methods from your answer, it was an extra character :sweat_smile: that's why when I add
/dev/null
to my second command did not work.