hide output of command while using cat and tee

12,692

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
Share:
12,692

Related videos on Youtube

Ahmad Abuhasna
Author by

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, 2022

Comments

  • Ahmad Abuhasna
    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:

    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).
  • Ahmad Abuhasna
    Ahmad Abuhasna about 6 years
    Thanks, 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.