DEV Community

Raunak Ramakrishnan
Raunak Ramakrishnan

Posted on

9 1

Setting display brightness on Linux from the command line

I auto-adjust the brightness on my display using a cron which runs at 7 pm everyday.

xrandr --output eDP-1 --brightness 0.9
Enter fullscreen mode Exit fullscreen mode

This sets the brightness to 90% of maximum brightness.

Working with Linux Display environments in a cron

The above command works when run from my terminal. But when run on a cron, it does not produce any effect. We need to explicitly mention the "display number" as an environment variable DISPLAY.

8 19 * * * DISPLAY=:0 xrandr --verbose --output eDP-1 --brightness 0.9
Enter fullscreen mode Exit fullscreen mode

How to get the display number of your monitor?

Running xrandr will give you a lot of output like

Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384
eDP-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis)
Enter fullscreen mode Exit fullscreen mode

In my case, the display number is :0

Adjusting backlight brightness vs perceived brightness

If xrandr is unable to find backlight, it only changes "perceived" brightness i.e it does software color correction. If we want to save battery, we will need to reduce the backlight brightness.

In Linux, the backlights can be found in /sys/class/backlight. In my case, it was /sys/class/backlight/intel_backlight. In this folder, there are many files like

actual_brightness
max_brightness
brightness
Enter fullscreen mode Exit fullscreen mode

max_brightness shows highest possible level of brightness for the display. We can adjust the value in brightness file to reduce backlight brightness.
Here's what I do to adjust it: echo 1800 > /sys/class/backlight/intel_backlight/brightness (in root crontab)

Unlike the xrandr command, this does not require setting any DISPLAY variable in the cron file.

Other tools

  • brightnessctl is an easy to use tool which integrates well with systemd. It is also available in the package managers of various distributions like Debian, Ubuntu, Arch Linux.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay