Sysfs

sysfs is a virtual filesystem (virtual means it takes up no disk space). It exports information about devices and drivers and is also used for configuration. It's generated by the kernel and always mounted at /sys.

Usage[edit | edit source]

Use cat to read the information. For example, to output the charging level of a battery:

user $cat /sys/class/power_supply/BAT0/status

Get the device name by listing the /sys/class/net directory contents using ls -al or the tree command (provided by the app-text/tree package):

user $tree /sys/class/net
/sys/class/net/
├── enp2s14 -> ../../devices/pci0000:00/0000:00:1e.0/0000:02:0e.0/net/enp2s14
├── lo -> ../../devices/virtual/net/lo
├── sit0 -> ../../devices/virtual/net/sit0
└── wlp8s0 -> ../../devices/pci0000:00/0000:00:1c.0/0000:08:00.0/net/wlp8s0

sysfs can be used to set values at runtime. For example, the echo command can be used to enable system suspension:

root #echo mem > /sys/power/state

To set values at boot time create a local.d script.

This article is issued from Gentoo. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.