$ echo hello | sudo tee -a /path/to/file
tee command copies standard input to standard output, making a copy in zero or more files.
- If the
-a flag is specified it appends instead of overwriting.
sudo makes it possible to write to files the current user has no permission to but root does.