Skip to content

Instantly share code, notes, and snippets.

@GordonGustafson
Created April 14, 2020 02:27
Show Gist options
  • Save GordonGustafson/07874ab9410d630da4a9039bd4a272f4 to your computer and use it in GitHub Desktop.
Save GordonGustafson/07874ab9410d630da4a9039bd4a272f4 to your computer and use it in GitHub Desktop.
Change linux screen brightness by a percentage
#!/usr/bin/env bash
# Mimics the functionality of xbacklight by directly writing to a file.
# Must be run as a user with permission to write to the brightness file.
#
# usage:
#
# sudo ./change_brightness.sh 10 # increase screen brightness by 10%
# sudo ./change_brightness.sh -10 # decrease screen brightness by 10%
BACKLIGHT_FILE=/sys/class/backlight/intel_backlight/brightness
PERCENTAGE_CHANGE=$1
# divide by one to round to an integer, since the file only accepts integer values
echo "((1 + 0.01 * $PERCENTAGE_CHANGE) * $(cat $BACKLIGHT_FILE))/1" | bc > $BACKLIGHT_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment