216

To work around bug #1005495 (changing LCD brightness via hotkeys impossible), I'd like to have one command line query for increasing and one for reducing the brightness of my LCD. I could then map a hotkey to each one of this queries.

The problem is: I don't know how to increase and reduce the LCD brightness on the command line. Do you?

Pablo Bianchi
  • 15,657
user69748
  • 2,373

18 Answers18

189

Open your terminal and type this

xrandr -q | grep " connected"

it will gives you the output as

LVDS1 connected 1680x1050+0+0 (normal left inverted right x axis y axis) 331mm x 207mm

There LVDS1 Stands for your display. So now you have to do as

xrandr --output LVDS1 --brightness 0.5

there 0.5 stands for brightness level and it ranges from 0.0 to 1.0 . 0.0 -> Full black .so you have to choose the required value of brightness .

This doesn't change brightness at a hardware level. From randr manual:

--brightness brightness Multiply the gamma values on the crtc currently attached to the output to specified floating value. Useful for overly bright or overly dim outputs. However, this is a software only modification, if your hardware has support to actually change the brightness, you will probably prefer to use xbacklight.

Pablo Bianchi
  • 15,657
Raja G
  • 102,391
  • 106
  • 255
  • 328
  • 2
    Thanks for you answer but what I'd need is something like xrandr --increase 10 to increase the brightness by 10 percent. Is that possible, too? – user69748 Dec 14 '12 at 11:50
  • @user69748 well, you could use my first answer for that purpose . – Raja G Dec 14 '12 at 17:21
  • thanks but that doesn't work for me as written there. – user69748 Jan 17 '13 at 16:01
  • 61
    this doesn't seem to change the brightness at a hardware level – erjoalgo Oct 18 '13 at 06:29
  • Elaborate the issue please – Raja G Oct 18 '13 at 06:36
  • In my case, the xrandr --output eDP1 --brightness 0.2 approach works fine while xbacklight -set 20 fails. And I have the same question as @user69748: is it possible to use xrandr to change brightness by +/-0.05? – landroni Apr 27 '14 at 07:37
  • @landroni lemme look – Raja G Apr 27 '14 at 08:48
  • @landroni xbacklight not having full support for some hardware. – Raja G Apr 28 '14 at 05:26
  • Ah, OK, thanks! So there is no way to +/-0.05 brightness for xrandr users? – landroni Apr 28 '14 at 06:22
  • 1
    Regarding user84207'c comment, then I fear the same: It seems that at 0.0, the screen is all black, but still lit up, making it seems that the screen lights are still firing away, wasting battery. So is the brightness just changed on the graphical level, comparable to changing the brightness of a photo or in a game? – Rasmus Oct 02 '14 at 08:23
  • 15
    Too bad this answer got so many votes. My laptop screen "emulates" darkness so to say by making things appear darker (just as when you play a video with a night scene, that has nothing to do with the screen lightness but rather with pixels masking the background light). The lightness is exactly the same, wasting even more battery than before because of the pixels than now are darker. – Mephisto Nov 16 '14 at 15:47
  • @Mephisto All Laptops are not same. All answers are not same. – Raja G Nov 17 '14 at 05:05
  • @Raja I have a question here that I think could use your input, Thanks – xtrchessreal Aug 23 '15 at 21:30
  • 7
    It fakes the brightness. The brightness does not change, it is rendered by software. – Eathen Nutt Apr 01 '16 at 20:58
  • @user1970939 I will try to update my answer. But please remember this answer was posted 4 years ago. – Raja G Apr 02 '16 at 04:49
  • 2
    I can confirm that this only emulates the brightness and does not change the brightness of the display's background light. Interestingly, the brightness of the mouse pointer is not changed, leaving it much brighter than the rest of the desktop. – nyi Apr 14 '16 at 08:24
  • Just what i needed xrandr --output LVDS-1 --brightness 0.08 for night – Neil Sep 06 '16 at 14:53
  • @Neil did you mean 0.8 rather than 0.08? – WinEunuuchs2Unix Jul 05 '18 at 01:42
  • 1
    In one line: xrandr --output $(xrandr -q | grep " connected" | col1 | tail -1) --brightness 0.9 – Pablo Bianchi Jan 04 '19 at 22:50
  • "it ranges from 0.0 to 1.0 . 0.0 " is not true. 20.04 I can change it to 1.1 – BaTycoon Jan 14 '22 at 18:25
  • Exactly, this does not change the brightness on the hardware level just like I can change it using the keyboard keys. xbacklight doesn't work for me either because I have Radeon GPU. – Vin Raghav Apr 09 '22 at 03:12
167

The following works for me:

echo 400 | sudo tee /sys/class/backlight/intel_backlight/brightness

I guess the maximum possible value is in the /sys/class/backlight/intel_backlight/max_brightness file.

Replace intel_backlight with an asterisk to apply to all backlights.

Pablo Bianchi
  • 15,657
palacsint
  • 2,147
  • 1
  • 15
  • 9
  • 1
    This is useful information but it doesn't work for me. Permission denied, even if I sudo. I also tried to vim the file and edit it, but it won't let me, saying something like "Fsync failed". – Ray Nov 27 '15 at 09:25
  • 18
    @Ray Try this: echo 400 | sudo tee /sys/class/backlight/intel_backlight/brightness. – Mygod Nov 28 '15 at 17:39
  • Oh wow it works! I'm not really Linux-savvy so as far as I'm concerned right now this is magic. – Ray Nov 30 '15 at 09:45
  • 11
    @Ray when you do sudo echo 400 > /sys/class . .. ./brightness redirection is done by shell , not by echo. And shell still runs as your regular user, not as sudo. That's why it gives permission denied. You need to have a utility that will write to file with root permissions, which is why tee works. – Sergiy Kolodyazhnyy Mar 09 '16 at 19:37
  • 4
    echo 400 | sudo tee /sys/class/backlight/radeon_bl0/brightness for radeon APUs and cards – Suici Doga Apr 01 '16 at 11:40
  • 14
    This is ridiculously low-level, but in fact seems to be the only thing that reliably works. It gets a bit less ugly if you sudo chmod 0646 the brightness file, so sudo isn't needed for setting brightness anymore. – leftaroundabout May 24 '16 at 21:00
  • 14
    The reason that this is set at su permissions is that a virus could conceivably make your screen dim and go bright at incredible speed ultimately damaging your hardware display. In the 90's I encountered a virus that would adjust the screen refresh Hertz so rapidly that your monitor would fry. So be careful tweaking the permissions on this. – RyanNerd Oct 21 '16 at 16:21
  • 2
    echo '30000' | sudo tee /sys/class/backlight/gmux_backlight/brightness for me – Colin Nov 05 '16 at 02:38
  • 3
    Instead of changing the permissions of the file, you can add a script to the sudoers as a NOPASSWD entry (and change the script's permissions to require root to edit it). From there you can implement timeouts and any other protections you see fit. Alternatively you could write a daemon to periodically copy the brightness setting from a writable local brightness file to the live one. Either method means you can bind keys to modify the brightness without entering a password or leaving the master unsecured. – John P Jan 23 '17 at 15:16
  • RyanNerd , really because monitors anyways change the brightness really quickly to make it dimmer or brighter using PWM. Also lightboost does change it really quickly too so i think that it does no damage – Suici Doga May 19 '17 at 10:43
  • I do sudo nano /sys/ ... /brightness then I can change the value and apply it with Ctrl O. On my system, if I set it to anything above 976 I get an "invalid argument" error. This seems to be the max brightness here. – Rolf Jan 01 '18 at 23:26
  • for me this worked well as su (not sudo) – Casper Gerritsen Feb 01 '18 at 07:51
  • 2
    Brilliant, thank you. With Ubuntu Server, or any headless system, you don't want to install an window manager just to get access to xrandr or have xbacklight work. This works perfectly on my MacBook Air running Ubuntu Server 19.04 without any extra packages required. – DanielSmedegaardBuus May 14 '19 at 15:44
  • sudo bash -c "echo 400 > /sys/class/backlight/intel_backlight/brightness" to give permission to bash managing redirection to file. – astasiak Feb 29 '20 at 01:38
  • …bypainstakingly narrowing down the interval I 'learned' that 4437 is the highest brightness level on my lenovo laptop. (4438 will get you an 'invalied argument' – Frank N Apr 11 '21 at 14:43
  • 1
    Thanks, +1. This works on Wayland too. The screen on my Dell Latitude 5590 didn't respond to any other control, and was nearly unreadable, at a value of 375 out of a maximum of 7500. – Jos Mar 24 '23 at 11:35
163

Note: xbacklight only works with Intel, not properly on Radeon and not at all with modesetting driver (source). It also only works on X11, not Wayland.


One more way we have to do this is with another new program named as xbacklight , open your terminal and type this

sudo apt-get install xbacklight

then type this xbacklight -set 50

there 50 stands for brightness range we can get it upto 100 from 0 .

you can also increase and decrease the brightness from present value to specified level.as you mentioned if you want to increase to 10% from current value of brightness then you can give this

xbacklight -inc 10

and to decrease 10% you can give this

xbacklight -dec 10 
Raja G
  • 102,391
  • 106
  • 255
  • 328
  • Looks like a really simple command but what I'd need is something like xbacklight -increase 10 to increase the brightness by 10 percent. Is that possible, too? – user69748 Aug 24 '12 at 09:31
  • @user69748 answer edited – Raja G Aug 24 '12 at 10:47
  • 1
    Yes you can. I've already mention that . so you can get that by xbacklight -inc 10 – Raja G Aug 24 '12 at 16:53
  • 44
    That really looks simple, but unfortunatelly it doesn't work for me. Brightness simply doesn't change, not with -dec and not with -set. I guess I'll have to hope the bug gets fixed any time soon. Thanks nevertheless. – user69748 Sep 04 '12 at 14:38
  • This works better than the xrandr thing on my Ubuntu 14.04 Lenovo laptop. setting the brightness via xrandr changes a different brightness setting, but xbacklight seems to change the same setting that the keyboard brightness buttons change – Michael Butler Jun 06 '15 at 18:26
  • It is very simple and thanks for that. It is working for me(Ubuntu 14.04, HP DV6), But it does not increase by the amount of 10%. I have used custom shortcut for the increase and decrease command, but they reach the 100 in just 4 clicks. and difference between the 3rd and 4rth times key press, there is more difference in the brightness compared to 1st, 2nd, 3rd key presses(when i start from lowest brightness). Can anybody tell me the reason behind it or point towards right direction. – hunch Jun 24 '15 at 17:05
  • Why is this answer not the accepted answer ? I have just tested on LTS 14.04 and it works like a charm. I like very much xbacklight -dec 1 to decrease from 1 unit until get get what you need. You get also get the current value. -get. – Rudy Vissers Feb 02 '16 at 06:56
  • 2
    Additionally, there's a shorthand you can use:

    xbacklight +10; xbacklight -10; xbacklight =50;

    – Fordi Mar 09 '16 at 18:48
  • worked great for me on 16.04.1-gnome. also hooked the +10/-10 up to my keyboard shortcuts that were previously not working using the gnome Keyboard app. – Joe Bergevin Oct 05 '16 at 17:44
  • My lubuntu 16.4. does not work with the --inc. I have two aliases: alias x+='xbacklight -set 40' (which is quite light) and alias x-='xbacklight -dec 10' – Timo Dec 09 '17 at 19:18
  • I have Radeon GPU and Intel processor. xbacklight has no effect on the brightness. – Vin Raghav Apr 09 '22 at 03:12
24

Using D-Bus with GNOME

You can increase/decrease brightness with gdbus:

# Step up
gdbus call --session --dest org.gnome.SettingsDaemon.Power --object-path /org/gnome/SettingsDaemon/Power --method org.gnome.SettingsDaemon.Power.Screen.StepUp

Step down

gdbus call --session --dest org.gnome.SettingsDaemon.Power --object-path /org/gnome/SettingsDaemon/Power --method org.gnome.SettingsDaemon.Power.Screen.StepDown

Notes

Pablo Bianchi
  • 15,657
13

For Laptops,

sudo setpci -s 00:02.0 F4.B=80

Change 80 by [0-FF] to get lowest-highest brightness. The value specified is in hex, so 80 will give you a 50% of max brightness.

For Desktops to make a gamma correction (not tested by me),

xgamma -gamma .75
Pablo Bianchi
  • 15,657
5

Make this script:

set-brightness.sh

#!/bin/bash
TARGET="acpi_video0"
cd /sys/class/backlight
MAX="$(cat "${TARGET}/max_brightness")"
# The `/1` at the end forced bc to cast the result 
# to an integer, even if $1 is a float (which it 
# should be)
LOGIC="$(echo "($1 * ${MAX})/1" | bc)"
for i in */; do
    if [[ "${TARGET}/" != "$i" && -e "${i}brightness" ]]; then
        cat "${i}max_brightness" > "${i}brightness"
    fi
done
echo "$LOGIC" > "${TARGET}/brightness"

Run it as root, with any value between 0 and 1.

sudo ./set-brightness.sh 0.5
  • If your system doesn't have an /sys/class/backlight/acpi_video0, there should be at least one directory in there, which may be device-specific (I also have a radeon_bl0, for example).
  • If you have others, keep in mind their values stack (hence the loop; pushing all the other values to 1.0, then setting the target one to the desired amount).
  • While acpi_video0 should always work, it doesn't always have the full range of physical brightnesses available. Try each one, and use the one with the largest gamut as your "TARGET"
muru
  • 197,895
  • 55
  • 485
  • 740
Fordi
  • 299
  • 4
    Consider using /sys/class/backlight/*/brightness instead of trying to hard-code acpi_video0 into the script. It will allow for generalizing the path to file, which can be different - i for example have intel_backlight, not acpi_video0. That's what I've used in my script here – Sergiy Kolodyazhnyy Mar 09 '16 at 19:41
4

KDE 4.12:

qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl setBrightness 55

KDE Plasma Version: 5.14.3:

The above code is still valid. It will only work if you are a KDE user. However in that case it will require no additional piece of software. It will have the exact same behavior as when using the "battery and brightness" widget. AFAIK it changes the physical backlight, in contrast with xrandr which does does not.

Beware that the 55 above is not a fraction of 100, the latter being the max brightness. Instead it is related to max_brightness:

qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl brightnessMax

There is also a "silent" version that you might prefer in a script:

qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl setBrightnessSilent 2000

Refs: qdbus, solid, brightness

int_ua
  • 8,574
3

To set absolute brightness (for laptop users):

BRIGHTNESS=50 # 0 to 100

dbus-send \
--session \
--type=method_call \
--dest="org.gnome.SettingsDaemon.Power" \
/org/gnome/SettingsDaemon/Power \
org.freedesktop.DBus.Properties.Set \
string:"org.gnome.SettingsDaemon.Power.Screen" \
string:"Brightness" \
variant:int32:$BRIGHTNESS
nvd
  • 1,160
  • 9
  • 7
3

Try this in terminal:

xrandr --output LVDS1 --brightness 0.9

You can change the last value as you like, eg. 0.2

Eric Carvalho
  • 54,385
  • 4
  • Output is not always LVDS1, but user can find out with xrandr --verbose
  • Doesn't change backlight intensity
  • – erjoalgo Oct 18 '13 at 06:31