The redirection operator is not part of your
sudo command. In other words, when you execute
sudo bash -c echo "profile" > /sys/class/drm/card0/device/power_method, what actually happens is:
- The shell executes
sudo bash -c echo "profile"
sudo, which has the setuid bit set, asks for your password, and forks the process
bash -c echo "profile" with EUID set to 0 (i.e., the command is executed as root)
bash command executes
echo "profile" and prints
profile to standard output as root.
- The shell running your original command takes the string from standard output and tries to redirect it to
/sys/class/drm/card0/device/power_method, which gets you a
Permission denied since the shell is not running with root privileges.
There are a number of ways to solve this. One is to give the entire string with the redirection operator as argument to
sudo bash -c 'echo "profile" > /sys/class/drm/card0/device/power_method'
I've also often seen people use
tee, which looks somewhat nicer (and doesn't execute the
echo command as root):
echo "profile" | sudo tee /sys/class/drm/card0/device/power_method
tee reads from standard input and outputs that to both standard output and all files you passed it as parameters.