3

On Ubuntu my Brightness keys don't work. So instead to open Ubuntu settings every time, I want to write a shell script to use in my .bashrc. Now I don't understand at all why the tee command in the following line seems to be neessary! Thanks!

sudo echo "937" | sudo tee /sys/class/backlight/intel_backlight/brightness 
Elder Geek
  • 35,476
  • 25
  • 95
  • 181
v217
  • 358
  • 1
  • 4
  • 15
  • 1
    because redirection will not work with sudo... there are other ways of doing it, but tee is nice – Zanna Oct 12 '16 at 13:43
  • 1
    So you understand what this command does and just don't know why `tee` is used or what? You can skip the first `sudo` )) and it will do same. – Pilot6 Oct 12 '16 at 13:44
  • @Zanna Why redirection does not work with sudo? – v217 Oct 12 '16 at 13:46
  • @Zanna Your comment is partly wrong. Even in root shell this does not work: root@mycomputer: echo "200" | /sys/class/backlight/intel_backlight/brightness bash: /sys/class/backlight/intel_backlight/brightness: Permission denied – v217 Oct 12 '16 at 13:47
  • @Zanna What other ways of doing it are there? – v217 Oct 12 '16 at 13:50
  • 1
    The thing that's really not necessary about this command is the `sudo` before `echo`. – UTF-8 Oct 12 '16 at 18:05

1 Answers1

5

tee is not necessary in that command.

You just need to edit the file /sys/class/backlight/intel_backlight/brightness to add 937, as the file is only writeable by the owner, root (user with UID 0), any manner that can do exactly that would suffice.

You could just do:

sudo bash -c 'echo "937" >/sys/class/backlight/intel_backlight/brightness' 

In that command, tee is being run with sudo i.e. being run as root as the file /sys/class/backlight/intel_backlight/brightness in only writable by root.

Even you can start an interactive-login session of your SHELL for root by:

sudo -i

and open-write-close the file with any command or your editor of choice (and later exit that session), but that would be clumsy and unnecessary as you want to run just a single command.

Also you don't need the sudo with echo, do:

echo "937" | sudo tee /sys/class/backlight/intel_backlight/brightness 
heemayl
  • 90,425
  • 20
  • 200
  • 267