sys
Practical examples for interacting with Linux sysfs (/sys) to inspect and configure hardware at runtime
Print fan speed in rpm by using awk
$ awk 'NR==1{l=$0;next}{print l ": " $0 " RPM"}' /sys/class/hwmon/hwmon0/fan1_label /sys/class/hwmon/hwmon0/fan1_input
CPU Fan Speed: 2847 RPM
Print fan speed in rpm
sed 's/^/Fan Speed: /g' /sys/class/hwmon/hwmon0/fan1_input
Print module names of hwmon
grep -R . /sys/class/hwmon/hwmon*/name
Read CPU fan speed (rpm) via hp-wmi-sensors
cat /sys/class/hwmon/hwmon*/fan*_input 2>/dev/null
Example 2: Read CPU fan speed (rpm) via hp-wmi-sensors
d=$(for x in /sys/class/hwmon/hwmon*; do [ -f "$x/name" ] && [ "$(cat "$x/name")" = "hp_wmi_sensors" ] && echo "$x" && break; done)
cat "$d"/fan*_input
Find the hp-wmi-sensors hwmon directory
for d in /sys/class/hwmon/hwmon*; do
[ -f "$d/name" ] && [ "$(cat "$d/name")" = "hp_wmi_sensors" ] && echo "$d"
done
Read cpu fan RPM (raw sysfs value)
HWMON=$(for d in /sys/class/hwmon/hwmon*; do
[ -f "$d/name" ] && [ "$(cat "$d/name")" = "hp_wmi_sensors" ] && echo "$d" && break
done)
cat "$HWMON"/fan*_input
Read cpu fan RPM with a label and values
for f in "$HWMON"/fan*_input; do
n=${f%_input}
label_file="${n}_label"
label=$( [ -f "$label_file" ] && cat "$label_file" || basename "$n" )
printf "%s: %s RPM\n" "$label" "$(cat "$f")"
done
Print current cpu speed
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq
Set scaling governor to perfomance
echo "performance" |tee /sys/devices/system/cpu/cpufreq/policy*/scaling_governor
Bios data is stored in /dmi folder
cat /sys/class/dmi/id/bios_date
List monitors
ls -1 /sys/class/drm | grep -E 'eDP|LVDS|DP|HDMI'
Holds power_supply settings
ls -1 /sys/class/power_supply
List USB devices by Vendor ID
awk -vRS= '/Vendor=0a12/{print $0,"\n"}' /sys/kernel/debug/usb/devices
Read battery percentage (laptops only)
cat /sys/class/power_supply/BAT0/{energy_full,energy_full_design,cycle_count}
ACPI thermal zones (throttling triggers)
cat /sys/class/thermal/thermal_zone*/{type,temp,trip_point_*}
Show temperatures of cpu
ls /sys/class/hwmon
cat /sys/class/hwmon/hwmon*/name
cat /sys/class/hwmon/hwmon*/temp*_input
cat /sys/class/hwmon/hwmon*/fan*_input
Read numa nodes and memory
cat /sys/devices/system/node/node*/meminfo
Read USB power / autosuspend
cat /sys/bus/usb/devices/*/power/{control,autosuspend}
USB descriptors (raw data)
cat /sys/bus/usb/devices/*/descriptors | hexdump -C
Read conneted monitors
cat /sys/class/drm/*/status
Read data about drives
ls /sys/block
cat /sys/block/sda/queue/{scheduler,rotational,read_ahead_kb}
I/O-statistik per drive
cat /sys/block/sda/stat
DebugFS mount (a lot of extra data)
mount | grep debugfs
ls /sys/kernel/debug
cpu scaling
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
Find network devices
for i in /sys/class/net/*; do
printf "%s\n" "$(basename "$i")"
ls -l "$i" | sed 's/^/└── /'
done
Set ENERGY_PERF_BIAS, 0 is highest perfomance and 15 is lowest
cat /sys/devices/system/cpu/cpu*/power/energy_perf_bias
Print scaling_driver in use
$ grep . /sys/devices/system/cpu/cpufreq/policy*/scaling_driver
/sys/devices/system/cpu/cpufreq/policy0/scaling_driver:intel_pstate
/sys/devices/system/cpu/cpufreq/policy1/scaling_driver:intel_pstate
/sys/devices/system/cpu/cpufreq/policy2/scaling_driver:intel_pstate
/sys/devices/system/cpu/cpufreq/policy3/scaling_driver:intel_pstate
Print scaling_available_governors info
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_governors
Print mac address for eno1
cat /sys/class/net/eno1/address
Print speed of network interface
cat /sys/class/net/eno1/speed
Print cpu temperature in celsius by reading temp file (posix compatible)
while read -r t; do
printf "%.2f°C\n" "$(echo "$t/1000" | bc -l)"
done < /sys/class/thermal/*/temp
Print cpu temperature in celsius by using awk
awk '{ printf "%.2f°C\n", $1/1000 }' /sys/class/thermal/*/temp
List all available display resolutions (per monitor via DRM)
cat /sys/class/drm/card0-DP-3/modes
cat /sys/class/drm/card0-HDMI-A-2/modes
cat /sys/class/drm/card0-DP-1/modes