为什么树不能完全列出/sys/class/hwmon?我怎么能那样做?

Sto*_*aft 3 sysfs tree sensors

如果我理解正确的话,在 Linux 中,一切都是一条路径,一直到每个硬件。我试图获取有关传感器结构的信息,所以我想我只会使用树来映射 hwmon 目录中的所有内容。但是,树在此目录中的行为与我习惯的不同。

当我在普通目录上运行 tree 时,我在不使用 -R 或 -L 标志的情况下获得了子目录结构:

$ tree /home
/home
??? boss
    ??? clones
    ??? Desktop
    ??? Documents
    ?   ??? modules.txt
    ?   ??? old_docs
    ?   ?   ??? assorted
    ?   ??? prepscript.txt
    ??? Downloads
    ??? Music
    ??? Pictures
    ??? Public
    ??? Templates
    ??? Videos

12 directories, 2 files
Run Code Online (Sandbox Code Playgroud)

但我尝试对 HWmon 做同样的事情,它只会深入一层,即使我确实使用了 -R 标志并且即使有更深的东西:

$ tree /sys/class/hwmon/
/sys/class/hwmon/
??? hwmon0 -> ../../devices/pci0000:40/0000:40:01.3/0000:43:00.0/hwmon/hwmon0
??? hwmon1 -> ../../devices/pci0000:00/0000:00:01.3/0000:09:00.0/hwmon/hwmon1
??? hwmon2 -> ../../devices/pci0000:40/0000:40:03.1/0000:44:00.0/hwmon/hwmon2
??? hwmon3 -> ../../devices/pci0000:00/0000:00:18.3/hwmon/hwmon3
??? hwmon4 -> ../../devices/pci0000:00/0000:00:19.3/hwmon/hwmon4
??? hwmon5 -> ../../devices/virtual/thermal/thermal_zone0/hwmon5
??? hwmon6 -> ../../devices/platform/nct6775.656/hwmon/hwmon6

7 directories, 0 files
$ tree /sys/class/hwmon/hwmon0
/sys/class/hwmon/hwmon0
??? device -> ../../../0000:43:00.0
??? fan1_input
??? name
??? power
?   ??? async
?   ??? autosuspend_delay_ms
?   ??? control
?   ??? runtime_active_kids
?   ??? runtime_active_time
?   ??? runtime_enabled
?   ??? runtime_status
?   ??? runtime_suspended_time
?   ??? runtime_usage
??? pwm1
??? pwm1_enable
??? pwm1_max
??? pwm1_min
??? subsystem -> ../../../../../../class/hwmon
??? temp1_auto_point1_pwm
??? temp1_auto_point1_temp
??? temp1_auto_point1_temp_hyst
??? temp1_crit
??? temp1_crit_hyst
??? temp1_emergency
??? temp1_emergency_hyst
??? temp1_input
??? temp1_max
??? temp1_max_hyst
??? uevent
??? update_interval

3 directories, 27 files
Run Code Online (Sandbox Code Playgroud)

是什么导致了这种行为差异,我能否获得所有设备的简单树?

Ste*_*itt 8

tree这样做是因为默认情况下它不会取消引用符号链接。该-l选项将改变:

tree -l /sys/class/hwmon/
Run Code Online (Sandbox Code Playgroud)

但是你会很高兴理解所有的输出。

  • @Thoughtcraft 问题主要是因为“设备”链接在树上向上(到父设备),因此此命令显示整个设备树,而不仅仅是几个子树。我想你可以做例如 `tree -d /sys/class/hwmon/*/` 来显示目录结构和目录的符号链接,并自己追踪 `device` 链接。 (2认同)