“/sys”目录有什么用?

Che*_*603 25 filesystem sysfs directory-structure

不久前,我注意到了这个我以前从未见过的目录,/sys. 我研究了一下,读到“现代 Linux 系统”通常有这个目录,并且它管理设备。我认为这就是 /dev 的用途。我似乎无法找到一大堆的这个目录中,比我提到的其他,以及有关信息这一点,从引用页面:

/sys 是一个虚拟文件系统,可以访问它以设置或获取有关内核对系统视图的信息。

我已经运行 Trusty 一段时间了,之前从未注意到它,这就是为什么我觉得它有点奇怪。有人请填写我吗?这和 /dev 有什么区别?Ubuntu 什么时候开始使用这个目录,为什么?谢谢。

mur*_*uru 40

/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.
Run Code Online (Sandbox Code Playgroud)

例如:

等等...

  • @BhavikShah 你没有从这里删除任何东西 - 这些文件实际上并不存在。您必须删除所涉及的模块。 (3认同)