Append line to /etc/hosts file with shell script

前端 未结 7 1753
春和景丽
春和景丽 2021-01-30 08:41

I have a new Ubuntu 12.04 VPS. I am trying to write a setup script that completes an entire LAMP installation. Where I am having trouble is appending a line to the /etc/ho

7条回答
  •  再見小時候
    2021-01-30 08:58

    If your in mac or you need sudo permission to this try this:

    sudo -- sh -c -e "echo '192.34.0.03   subdomain.domain.com' >> /etc/hosts";
    

    It will still ask you for password.

    alternative way from @kainjow

    echo '192.34.0.03 subdomain.domain.com' | sudo tee -a /etc/hosts
    

提交回复
热议问题