Linux Command Reference ยท Special Files and Directories
The /sys filesystem
Reference for /sys (sysfs): the layout of block, net, class and devices directories, reading device attributes, writing settings as root, and how udev uses it.
/sys is sysfs, a virtual filesystem that presents the kernel's view of hardware, drivers and other kernel objects as directories and small files. Where /proc grew organically and mixes processes with hardware information, /sys is organized: one directory per object, one file per attribute, and symbolic links for relationships (a network card links to its PCI device, a disk to its controller).
Most attributes are plain text that you can read with cat. A few are writable by root and change device behavior, such as the I/O scheduler of a disk or the brightness of a screen. Tools like lsblk, lspci and udev are built on top of it.
cat /sys/class/net/eth0/address ls /sys/block echo 128 | sudo tee /sys/block/sda/queue/read_ahead_kb
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
The top-level directories:
| Directory | Description |
|---|---|
/sys/block |
Block devices (disks, partitions via subdirectories), with queue/, size, removable. |
/sys/class |
Devices grouped by function: net, block, tty, power_supply, backlight, thermal. |
/sys/devices |
The real device tree; class entries link here. |
/sys/bus |
Buses and the drivers bound to them (pci, usb, scsi). |
/sys/module |
Loaded kernel modules and their parameters. |
/sys/fs |
Filesystem-specific controls such as cgroup, btrfs, ext4. |
/sys/kernel |
Kernel features: mm/transparent_hugepage, debug, security. |
/sys/power |
Suspend and hibernate controls. |
Edge cases: attribute values end with a newline; sizes in block/*/size are in 512-byte sectors regardless of the real sector size. Some files are write-only triggers (for example rescan).
Usage notes
- Changes are temporary. Writes affect the running kernel only. Make them permanent with a udev rule, a
tmpfiles.dentry or a boot script. - Needs root to write, but nearly everything is world-readable. A few files, like some
powerordebugentries, are root-only. - Symlinks are the map.
readlink -f /sys/class/net/eth0reveals the PCI path of the card; the same trick finds which controller a disk hangs off. - Useful reads:
/sys/class/power_supply/BAT0/capacity(battery percent),/sys/class/thermal/thermal_zone0/temp(millidegrees Celsius),/sys/block/sda/queue/rotational(1 for spinning disks). - Not a configuration store. Permanent settings belong in config files;
/sysshows and tweaks live state. - Containers often see a read-only or partial
/sys. - Module parameters:
/sys/module/NAME/parameters/lists tunables a module exposes; many are read-only after load.
Related
/proc/sys,/dev/null,/boot- Lessons: Disks and logs, Boot and kernel