/sys
是旧的。它是在Linux内核达到2.6(在进行2.4 / 2.5拆分时返回)之前引入的。自从第一个Ubuntu版本使用2.6内核以来,每个版本的Ubuntu都有一个/sys
。
/dev
包含实际的设备文件。它不提供对内核知道的所有设备的访问(例如,以太网设备)- 为什么网络接口不像其他设备一样在/ dev中,为什么以太网设备不显示在“ / dev”中?)。它是设备本身的接口-您写入设备,从设备读取等。
/sys
是内核的接口。具体来说,它提供了类似于文件系统的内核提供的信息和配置设置的视图/proc
。根据要更改的设置,写入这些文件可能写入也可能不会写入实际设备。尽管这是一个常见的用例,但它不仅用于管理设备。
可以在内核文档中找到更多信息:
Top Level Directory Layout
~~~~~~~~~~~~~~~~~~~~~~~~~~
The sysfs directory arrangement exposes the relationship of kernel
data structures.
The top level sysfs directory looks like:
block/
bus/
class/
dev/
devices/
firmware/
net/
fs/
devices/ contains a filesystem representation of the device tree. It maps
directly to the internal kernel device tree, which is a hierarchy of
struct device.
bus/ contains flat directory layout of the various bus types in the
kernel. Each bus's directory contains two subdirectories:
devices/
drivers/
devices/ contains symlinks for each device discovered in the system
that point to the device's directory under root/.
drivers/ contains a directory for each device driver that is loaded
for devices on that particular bus (this assumes that drivers do not
span multiple bus types).
fs/ contains a directory for some filesystems. Currently each
filesystem wanting to export attributes must create its own hierarchy
below fs/ (see ./fuse.txt for an example).
dev/ contains two directories char/ and block/. Inside these two
directories there are symlinks named <major>:<minor>. These symlinks
point to the sysfs directory for the given device. /sys/dev provides a
quick way to lookup the sysfs interface for a device from the result of
a stat(2) operation.
例如:
设置笔记本电脑显示器亮度的一种方法是:
echo N > /sys/class/backlight/acpi_video0/brightness
要获取网卡的MAC地址:
cat /sys/class/net/enp1s0/address
要获取当前的CPU缩放调节器:
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
等等...
/sys
现在已经有十多年了。