How does the vim “write with sudo” trick work?

In :w !sudo tee %… % means “the current file” As eugene y pointed out, % does indeed mean “the current file name”, which is passed to tee so that it knows which file to overwrite. (In substitution commands, it’s slightly different; as :help :% shows, it’s equal to 1,$ (the entire file) (thanks to … Read more

sudo echo “something” >> /etc/privilegedFile doesn’t work [duplicate]

Use tee –append or tee -a. echo ‘deb blah … blah’ | sudo tee -a /etc/apt/sources.list Make sure to avoid quotes inside quotes. To avoid printing data back to the console, redirect the output to /dev/null. echo ‘deb blah … blah’ | sudo tee -a /etc/apt/sources.list > /dev/null Remember about the (-a/–append) flag! Just tee … Read more

sudo in php exec()

It sounds like you need to set up passwordless sudo. Try: %admin ALL=(ALL) NOPASSWD: osascript myscript.scpt Also comment out the following line (in /etc/sudoers via visudo), if it is there: Defaults requiretty