In this lesson, you will learn how to interact directly with your hardware and kernel drivers by reading and writing to the virtual /sys filesystem.
What is Sysfs?
While /proc provides information about running processes, the /sys directory acts as a structured "control panel" for your computer’s hardware. It is a virtual filesystem—meaning it doesn't exist on your physical disk, but is generated in memory by the kernel. It exports information about devices, drivers, and kernel subsystems into a tree of files that you can interact with using standard shell commands like cat and echo.
Interacting with Hardware Settings
Every entry in /sys represents a component recognized by the kernel. For example, if you want to control the brightness of your laptop screen, you don't need a complex binary program; you can interact with the files directly.
Navigate into the class of backlights:
cd /sys/class/backlight/
If you list the files inside your specific backlight folder, you will see a file named brightness. You can check the current level with:
cat /sys/class/backlight/intel_backlight/brightness
To change the brightness, you can write a new integer value into that file. Since this requires high-level system privileges, you would use sudo:
echo 500 | sudo tee /sys/class/backlight/intel_backlight/brightness
Why use this instead of a tool?
When you use a GUI brightness slider or a keyboard shortcut, the operating system is almost always performing the exact action we just did: writing a value to a file in /sys. By understanding this interface, you gain a universal way to configure system hardware that works consistently, even when high-level tools are missing or malfunctioning.
Note that because these files reside in memory and represent the "live" state of the kernel, changes made here are volatile. If you reboot your computer, the kernel will reset these values to their default hardware states. This makes /sys the perfect place to experiment with hardware settings without risking permanent damage to your configuration.
Key Takeaway: The /sys filesystem provides a standardized, file-based interface that allows you to monitor and configure kernel-level hardware settings simply by reading from and writing to virtual files.