- 3 min read

How To Control Your Monitor Brightness From Command Line In Ubuntu?

Posted by Sandip Bhagat on October 1, 2015

I use a Ubuntu desktop with a LCD display. As a developer, working late night in front of a computer is very common for me. But working late night has got one problem. The brightness of my monitor is usually very high which affects the eyes in the long run. Though, I could adjust the brightness from monitor settings with its hardware buttons but after adjusting, the display of my monitor doesn’t looks that good. If it was a laptop, the task is very easy as there are some dedicated keys to control the brightness which makes it easy to adjust the brightness on demand.

After searching in Google, I found some applications and tried those but for some reason they didn’t work for me. Then I got to know about xrandr command. I can use this to control the brightness of my screen and the best thing is, I don’t need to install this as it comes with Ubuntu already.

Here is the process to adjust the brightness of your screen.

  • First open a terminal with Ctrl + Alt + T
  • Type xrandr | grep " connected" | cut -f1 -d " " to find your monitor’s name
  • Now type xrandr --output your-monitor-name --brightness brightness-level

For example

$ xrandr | grep " connected" | cut -f1 -d " "
$ xrandr --output VGA1 --brightness 0.7

In my case, the name of my monitor was VGA1 so, I used VGA1 as the monitor name and changed my brightness to 0.7.

Note: The brightness level must be between 0 to 1 with 0 being the dimmest and 1 being the brightest.

I have created a script to adjust the screen brightness.

Adding script to startup

If you have restarted your computer then you might have realized that the changes are lost. Whenever you change brightness using xrandr command, the change is temporary and is lost when you reboot your computer. Everytime, you reboot your computer, you need to type these commands again to adjust the brightness.

In order to avoid typing the command everytime, we can create a script that will run everytime the computer boots.

  • Create dimmer-startup.sh file at ~/dimmer-startup.sh
  • Copy the below code to dimmer-startup.sh file.
# Bash script to control the monitor brightness
screenname=$(xrandr | grep " connected" | cut -f1 -d" ")
xrandr --output $screenname --brightness $brightness_level;
  • Give execute permission to dimmer-startup.sh file by typing sudo chmod +x ~/dimmer-startup.sh
  • You can change the value of brightness_level variable to your taste. It must be between 0 to 1.
  • Create Dimmer.desktop file at ~/.config/autostart/Dimmer.desktop
  • Copy the below code to Dimmer.desktop file.
[Desktop Entry]
Name=Dimmer Script
GenericName=Dimmer Script
Comment=Dimmer App to control screen brightness
  • Replace user-name with your account username

Now, whenever your computer boots, the scripts runs automatically and your screen brightness is adjusted.