如何检查 ubuntu 上的平台是笔记本电脑还是台式机



检查执行平台是笔记本电脑还是台式机的最简单方法是什么?如果我需要检查/sys/class/power_supply/中的文件,我应该选择哪个文件?谢谢

您只认为您关心区分笔记本电脑和台式机。你真正关心的只是/sys/class/power_supply/是否存在。

if [ -d "/sys/class/power_supply" ]; then
    # Work with the files in /sys/class/power_supply
fi

检查是否有盖子怎么样?这应该适用于 Ubuntu – acpi:

if [ -d "/proc/acpi/button/lid" ]; then
    echo "computer is a laptop"
fi

检查是否有电池。如果它有电池,那么笔记本电脑。如果没有,那么电脑。

#!/bin/bash
# Run upower to check battery charge level.
LEVEL="$(upower -i $(upower -e | grep 'BAT') | grep -E "percentage" | awk '{print $2}' | sed 's/%//g')"
if [ $LEVEL -le 100 ]; then
    echo "Device is equipped with a battery and may be a laptop."
else
    echo "Device is NOT equipped with a batter and is likely a desktop."
fi

最新更新