You can get a list of all controllable LEDs by checking the content of the virtual directory /sys/class/leds
:
$ ls /sys/class/leds/
input5::capslock input5::numlock input5::scrolllock
On my system, there are only the three keyboard LEDs. If your output looks different, make sure you use the correct names instead below!
Each file is a symbolic link to a directory holding several properties of that LED:
$ ls '/sys/class/leds/input5::capslock'
brightness device max_brightness power subsystem trigger uevent
The only thing which is important for us is the brightness
file content.
0
means the LED is off.
1
means the LED is on. (Assuming the max_brightness
file holds the value 1 - on special keyboards the LED might maybe support multiple brightness values?)
We get the current LED state by checking the brightness
file's content (it's currently off):
$ cat '/sys/class/leds/input5::capslock/brightness'
0
To switch the LED on, we must set that file's content to 1
:
$ echo 1 | sudo tee '/sys/class/leds/input5::capslock/brightness'
1
To switch the LED on during every boot, you might want to append the command below to your /etc/rc.local
script. It will be executed as root, therefore we don't need the sudo tee
but can use Bash output redirection:
$ echo 1 > '/sys/class/leds/input5::capslock/brightness'