0

I often encouter this problem and it really bugs me on why it is so. So let's take this example into account :

[me@localhost:~]$ sudo command > /some/file.log

As far as I know, this will not work if the user has no permission to write in /some/file.log, even if the command is executed as sudo. I found some workarounds on this website so that's not a problem, but I would like to know what is the reason behind it ? Why would the command be executed as sudo, and the redirection as user ? Any solid reason to back this up ?

1 Answers1

1

You sudo the command command, the redirection of the output to /some/file.log is done by your current shell, which is running as the normal user.

What you could try in order to get the output written by root is:

sudo bash -c "command > /some/file.log"
Anthon
  • 79,293