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?
217 Answers
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.5there 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:
21
--brightness brightnessMultiply 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.
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 xbacklightthen 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 10and to decrease 10% you can give this
xbacklight -dec 10 11 The following works for me:
echo 400 | sudo tee /sys/class/backlight/intel_backlight/brightnessI 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.
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.StepDownNotes
- No root privileges needed! Unlike the
/sys/class/backlightway. - Source: Arch wiki (here for keyboards).
xbacklightnot always work.xrandrjust does a gamma correction.- Probably works on MATE and Xfce. For KDE check this answer, using
qdbus. ddcutilmight work on external monitors with DDC support
For Laptops,
sudo setpci -s 00:02.0 F4.B=80Change 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 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 aradeon_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_video0should 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"
Try this in terminal:
xrandr --output LVDS1 --brightness 0.9You can change the last value as you like, eg. 0.2
1Here's a short line that can help you relax your eyes. Just create a crontaab with the line or make a script
xrandr --output VGA1 --brightness 0.5; sleep 20; xrandr --output VGA1 --brightness 1 As @palacsint said, echo 244 > /sys/class/backlight/intel_backlight/brightness path works for me.
But max and min values are resent in /sys/class/backlight/intel_backlight/max_brightness and /sys/class/backlight/intel_backlight/bl_power files respectively.
Also, the actual brightness that your computer is running now is present in /sys/class/backlight/intel_backlight/actual_brightness
KDE 4.12:
qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl setBrightness 55KDE 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 brightnessMaxThere is also a "silent" version that you might prefer in a script:
qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl setBrightnessSilent 2000Refs: qdbus, solid, brightness
1ddccontrol is another option for controlling backlighting for external monitors. Here I can set the backlight of my external monitor to 50% of its power with:
ddccontrol -p -r 0x10 -w 50I looked in possible solutions for this problem to improve the way Redshift handles brightness changes. Through there I found that there is a patchset for the Linux kernel to improve compatibility across devices, so that laptops and external screens could work similarly, through sysfs.
In the meantime, ddccontrol is the only thing that works for me here. As usual, the Arch wiki has good overall documentation on the topic as well.
Using the above answers, I created this script (saved in my home directory as brightness.sh) to modify display brightness (as the laptop's keyboard suffered a spilled tea issue and became unusable). Feel free to use it (if you have the designated files... otherwise tinkering to point to your variation of them will be necessary).
#!/bin/bash
function main_menu { sudo clear cursetting=$(cat /sys/class/backlight/intel_backlight/brightness) maxsetting=$(cat /sys/class/backlight/intel_backlight/max_brightness) powersave=$((maxsetting/5)) conservative=$((powersave*2)) medium=$((powersave*3)) performance=$((powersave*4)) echo "" echo "----------------------- Brightness -----------------------" echo " 1. Set Display to Minimum (Powersave) brightness setting." echo " 2. Set Display to Low (Conservative) brightness setting." echo " 3. Set Display to Medium brightness setting." echo " 4. Set Display to High (Performance) brightness setting." echo " 5. Set Display to Maximum brightness setting." echo " 6. Exit." echo "----------------------------------------------------------" if [ $cursetting -eq $powersave ]; then cursetting='Minimum' else if [ $cursetting -eq $conservative ]; then cursetting='Conservative' else if [ $cursetting -eq $medium ]; then cursetting='Medium' else if [ $cursetting -eq $performance ]; then cursetting='Performance' else if [ $cursetting -eq $maxsetting ]; then cursetting='Maximum' fi fi fi fi fi echo " Current Display Setting - "$cursetting; choice=7 echo "" echo -e "Please enter your choice: \c"
}
function press_enter { echo "" echo -n "Press Enter to continue." read main_menu
}
main_menu
while [ $choice -eq 7 ]; do read choice if [ $choice -eq 1 ]; then echo $powersave | sudo tee /sys/class/backlight/intel_backlight/brightness main_menu else if [ $choice -eq 2 ]; then echo $conservative | sudo tee /sys/class/backlight/intel_backlight/brightness main_menu else if [ $choice -eq 3 ]; then echo $medium | sudo tee /sys/class/backlight/intel_backlight/brightness main_menu else if [ $choice -eq 4 ]; then echo $performance | sudo tee /sys/class/backlight/intel_backlight/brightness main_menu else if [ $choice -eq 5 ]; then echo $maxsetting | sudo tee /sys/class/backlight/intel_backlight/brightness main_menu else if [ $choice -eq 6 ]; then exit; else echo -e "Please enter the NUMBER of your choice: \c" choice = 7 fi fi fi fi fi fi
done 1 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 Based on placsint's answer
cd /sys/class/backlight/intel_backlight/
cat max_brightness | sudo tee brightness 1 Interactive ncurses-like UI using xbacklight
A poor man's ncurses. Hit h and it goes down 10%, hit l and it goes up 10%. Then show the current luminosity.
xback() ( done=false; echo "less: h, more: l, quit: q" while ! $done; do read -rsn1 key if [ "$key" = h ]; then xbacklight -dec 10 elif [ "$key" = l ]; then xbacklight -inc 10 elif [ "$key" = q ]; then done=true fi printf "\r$(xbacklight -get) " done
) I am using i3 as my window manager and I had uninstalled gnome, so the gnome solution didn't work for me. And the other software based approaches just made the screen look more black. So, after a bit of reading, I came across brightctl. Install it using apt install.
sudo apt install brightctlYou will need permissions to modify the display device, which only members of the group video(and obviously root) can do. So, make sure you add the current user to the video group. You can do this like so :
sudo usermod $(whoami) -a -G videoAfter installation, I can increase/decrease brightness using the below commands by 10 -- this is very gradual and gives me more control. :
#Increase brightness
/usr/bin/brightnessctl -d intel_backlight set +10
#Reduce brightness
/usr/bin/brightnessctl -d intel_backlight set 10-I have added keybindings in my i3 config. Here is a snippet of the keybinding.
#Increase brightness
bindsym XF86MonBrightnessUp exec /usr/bin/brightnessctl -d intel_backlight set +10
#Reduce brightness
bindsym XF86MonBrightnessDown exec /usr/bin/brightnessctl -d intel_backlight set 10- To increase brightness using xdotool, run the following command:
$ xdotool key XF86MonBrightnessUpTo decrease brightness using xdotool, run the following command:
$ xdotool key XF86MonBrightnessDown Since xdotool simulates real hardware keypresses, this is a hardware level change of brightness.
Source: