The error
The following command does not work:
$ sudo echo test >> /file/thare/requires/sudo
bash: /file/thare/requires/sudo: Permission denied
The fixed command
Use sudo tee -a
instead.
$ echo test | sudo tee -a /file/thare/requires/sudo
For example:
$ echo '127.0.0.1 localhost.example.com' | sudo tee -a /etc/hosts