Setting screen brightness from the command line
There are times when you need to be able to adjust the screen brightness from the terminal, or there are times when you find that the brightness controls are too coarse, and you need something that allows fine grained control over the brightness level. If you are using Debian or Ubuntu, this can be solved using a bash script.
#!/bin/bash BRIGHTNESS_FILE='/sys/class/backlight/intel_backlight/brightness' # If the file used to control brightness does not exist. if [[ ! -f "${BRIGHTNESS_FILE}" ]]; then echo 'This script does not work on this system.' exit 1 fi if [[ -z $1 ]]; then # Display the current brightness level. cat "${BRIGHTNESS_FILE}" elif [[ $1 =~ ^[0-9]+$ ]]; then # Check for positive integer. # Set the brightness level. echo "$1" | sudo tee "${BRIGHTNESS_FILE}" else echo 'Enter a positive integer for the brightness level.' exit 1 fi
The script assumes that you are using Debian or Ubuntu. I usually place this script in ~/bin/brightness
. That way, it can be used directly in bash (i.e. brightness
). If no arguments are provided, the script prints the current brightness level. If an integer argument is provided, the script sets the brightness level. Remember to make the script executable (chmod u+x ~/bin/brightness
), and the script should work as expected. You may be prompted for your sudo password to set the brightness level. I have not found a way that does not require extra privileges. I hope to find one soon.