Monday, January 21, 2013

One line command to add host in /etc/hosts at mac os


If i simply echo and output to /etc/hosts, i will get permission denied



sudo echo 127.0.0.1 myhelloword.localhost >> /etc/hosts
-bash: /etc/hosts: Permission denied


That's because echo is being run as root, but shell is the one who actually performing the redirection. The solution will be spawn a new shell to make this work:


sudo -- sh -c "echo 127.0.0.1 myhelloword.localhost >> /etc/hosts"

No comments: