How to change the Screen Brightness from cmd line?

Is there a command to change the Screen Brightness from the terminal/ssh cmd line? The background of my question is that the L5 sometimes wakes up with the screen nearly dark. I’ve disabled Automatic Brightness and do not see how this is done by the phone itself.

You have to edit the file /sys/class/backlight/backlight-dsi/brightness. Enter a byte value (number from 0 to 255) and save it. Brightness will change instantly.

Edit:
However, in my opinion it’s easier to just drag down the top panel and dot-wise touch (not swipe!) from right top to bottom in little steps on the screen. You will automatically increase brightness without seeing sliders.

Thank you! Just for the record: a good command to run is this:

$ echo 200 | sudo tee /sys/class/backlight/backlight-dsi/brightness
200

Re/ your hint tapping down, it took me a while to understand: you mean tapping down until one hits the slider line, yes?

1 Like

You’re welcome. Sorry that I described my hint not well enough. You’re correct, try it out.

And any idea what is changing the brightness?

do you have any scripts running? tlp?

I know this is an old thread but I’m trying to get this command to work in a script without prompting for a password as I want the brightness to change to different values automatically depending on whether or not the phone is docked or not. I’ve tried using sudoers.d and entering in specifics for my script but cannot get it to work.

Has anyone gotten this to work?

1 Like

I haven’t tried this particular issue, but I do have experience trying to get around sudo password prompts. The main problem is that *nix kernels generally don’t respect setuid on root owned scripts. Therefore you need to wrap your script in an actual BINARY that allows setuid. Here is an example minimal C program (which can be compiled with simply “gcc file.c”) which enables setuid, and runs a script at /opt/myscript.sh with one or two arguments passed from the binary to the script:

// sprintf()
#include <stdlib.h>
// system()
#include <stdio.h>
// setuid()
#include <unistd.h>
#define bufsize 1000
int main(int argc, char ** argv){
    char buffer[bufsize];
    setuid(0);
    sprintf(buffer, "/opt/myscript.sh %s %s", argv[1], (argc > 2)? argv[2] : "");
    system(buffer);
}

Make sure to set the setuid bit on the executable binary you produce with gcc (i.e. “chmod u+s mybinary”). In this case “/opt/myscript.sh” should be your script that requires sudo.

1 Like

Better done via /etc/sudoers and in particular a NOPASSWD option on a line if that’s what you want? Unfortunately @raenrfm hasn’t said what she tried that didn’t work.

In either case though care should be taken to make sure that you aren’t introducing a security hole.

1 Like

I tried putting a file in the sudoer.d directory with the script path and a NOPASSWD statement but could not make that work.

1 Like