-1

I have a problem, during write something into a root file:

$ ll /sys/bus/usb/devices/3-2/power/wakeup
-rw-r--r-- 1 root root 4096 Feb 16 17:28 /sys/bus/usb/devices/3-2/power/wakeup
$ sudo echo disabled > /sys/bus/usb/devices/3-2/power/wakeup
bash: /sys/bus/usb/devices/3-2/power/wakeup: Permission denied

even it did not ask me for password.

  1. How can I solve this?
  2. Why I can't use sudo directly?
How Chen
  • 255

1 Answers1

1

You cannot use sudo with redirection, because the redirection is done by your original shell which runs as your own user code. It tries to set up a file descriptor for the file mentioned after the >, which fails as your user is not able to write to it.

Costas's method works, as does spawning a subshell:

sudo sh -c "echo disabled > /sys/bus/usb/device/3-2/power/wakeup"