3 ms·
One trick that isn't a redirection feature of the shell itself, but comes in very handy is to use/misuse `tee` in combination with `sudo` to write files with di
by neilv 5y ago
One trick that isn't a redirection feature of the shell itself, but comes in very handy is to use/misuse `tee` in combination with `sudo` to write files with different privileges and ownership:
echo "my_system_config ${MyVar}" | sudo tee /etc/my-config-file
And with here-documents:
sudo tee /etc/my-config-file <<EOH
line one
line ${MyVar}
line three
EOH
- jstanley 5y agoAnd in vim if you accidentally open a root-owned file as your user, but want to save it anyway, you can ":w | sudo tee %" to get your changes saved.
- raffraffraff 5y ago+1 My favourite muscle-memory fix to the lack of "sudo vi" muscle memory