Skip to content

Instantly share code, notes, and snippets.

@VictorHugoBatista
Created September 24, 2025 20:59
Show Gist options
  • Select an option

  • Save VictorHugoBatista/e39d05db80ea7b9362b9279435644fe6 to your computer and use it in GitHub Desktop.

Select an option

Save VictorHugoBatista/e39d05db80ea7b9362b9279435644fe6 to your computer and use it in GitHub Desktop.
#!/bin/bash
# https://bbs.archlinux.org/viewtopic.php?id=134972
# How to run: ./brightness.sh -3 #(-3% of brightness)
# base dir for backlight class
basedir="/sys/class/backlight/"
# get the backlight handler
handler=$basedir$(ls $basedir)"/"
# get current brightness
old_brightness=$(cat $handler"brightness")
# get max brightness
max_brightness=$(cat $handler"max_brightness")
# get current brightness %
old_brightness_p=$(( 100 * $old_brightness / $max_brightness ))
# calculate new brightness %
new_brightness_p=$(($old_brightness_p $1))
# calculate new brightness value
new_brightness=$(( $max_brightness * $new_brightness_p / 100 ))
# set the new brightness value
sudo chmod 666 $handler"brightness"
echo $new_brightness > $handler"brightness"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment