如何从Linux终端检查笔记本电池状态

时间:2020-03-05 15:26:08  来源:igfitidea点击:

如果你太怪一了,那么像我一样怪人,想要从命令行检查甚至检查电池状态。
我们可以轻松获取GUI的电池状态,但如果我们希望从命令行的所有电池相关信息,那么听起来不错?
好的,我们将看到两个Linux命令在本文中找到电池相关信息。

电池状态和ACPI信息存储在/proc和/sys目录中。

使用"upower"命令或者"acpi"命令我们可以获得此信息。

upower命令

upower是一个命令行工具,它提供了一个界面,以枚举系统上的电源。
在终端中执行以下命令。
我们可以通过执行"upower -e"来获得"/org/..."路径。
此命令将显示有关电池的详细信息。
命令的输出很容易理解。

$upower -i /org/freedesktop/UPower/devices/battery_BAT1
  native-path:          BAT1
  vendor:               13-14
  model:                OA04041
  serial:               08726 06/19/2014
  power supply:         yes
  updated:              Tuesday 15 August 2016 11:41:01 PM IST (23 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               discharging
    energy:              18.7664 Wh
    energy-empty:        0 Wh
    energy-full:         32.2048 Wh
    energy-full-design:  32.2492 Wh
    energy-rate:         10.0936 W
    voltage:             14.982 V
    time to empty:       1.9 hours
    percentage:          58%
    capacity:            99.8623%
    technology:          lithium-ion
  History (charge):
    1502820602	58.000	discharging
  History (rate):
    1502820661	10.094	discharging
    1502820602	8.895	discharging
    1502820572	8.791	discharging

我们可以使用像Grep这样的工具过滤从所有输出中获取所需的信息。
现在,我只想看到舞台上的重要信息,剩余的时间待全面充电,电流电池级百分比。
因此,我们可以通过执行下面的命令来获得。

$upower -i /org/freedesktop/UPower/devices/battery_BAT1|grep -E "state|to\ full|percentage"
    state:               charging
    time to full:        1.7 hours
    percentage:          54%

acpi命令

ACPI命令显示来自/proc和/sys目录和电池状态的ACPI的Infromation。
我们可能必须在系统上安装ACPI。

要安装它,首先,通过在系统上执行以下命令更新存储库中可用的包列表

$sudo apt-get update

现在,执行以下命令以安装ACPI

sudo apt-get install acpi

很棒,现在安装了ACPI。

现在,执行命令"acpi -v"。
它将为我们提供有关电池的详细信息。

$acpi -V
Battery 0: Charging, 62%, 00:49:20 until charged
Battery 0: design capacity 2116 mAh, last full capacity 2116 mAh = 100%
Adapter 0: on-line
Thermal 0: ok, 27.8 degrees C
Thermal 0: trip point 0 switches to mode hot at temperature 83.0 degrees C
Thermal 1: ok, 50.0 degrees C
Thermal 1: trip point 0 switches to mode critical at temperature 105.0 degrees C
Thermal 1: trip point 1 switches to mode passive at temperature 108.0 degrees C
Thermal 2: ok, 50.0 degrees C
Thermal 2: trip point 0 switches to mode critical at temperature 105.0 degrees C
Thermal 2: trip point 1 switches to mode active at temperature 100.0 degrees C
Thermal 2: trip point 2 switches to mode active at temperature 55.0 degrees C
Cooling 0: x86_pkg_temp no state information available
Cooling 1: intel_powerclamp no state information available
Cooling 2: Processor 0 of 10
Cooling 3: Processor 0 of 10
Cooling 4: Processor 0 of 10
Cooling 5: Processor 0 of 10
Cooling 6: Fan 0 of 1

执行acpi命令查看电池状态

$acpi
Battery 0: Charging, 63%, 00:47:24 until charged

我们可以通过执行以下命令检查电池温度。
在Fahrenheit中看到最后的'-f'。

$acpi -t
Thermal 0: ok, 44.5 degrees C

如果要检查电源适配器,请执行以下命令。

$acpi -a
Adapter 0: on-line

ACPI有许多可以运行的选项。
只需运行"Man Acpi",我们将获得更多选项

$man acpi
OPTIONS
       -b | --battery
                 show battery information
       -a | --ac-adapter
                 show ac adapter information
       -t |  --thermal
                 show thermal information
       -c | --cooling
                 show cooling device information
       -V | --everything
                 show every device, overrides above options
       -s | --show-empty
                 show non-operational devices
       -i | --details
                 show additional details if available:
                 * battery capacity information
                 * temperature trip points
       -f | --fahrenheit
                 use fahrenheit as the temperature unit instead of default celsius
       -k | --kelvin
                 use kelvin as the temperature unit instead of default celsius
       -p | --proc
                 use the old /proc interface, default is the new /sys one
       -d | --directory 
                 path to ACPI info (either /proc/acpi or /sys/class)
       -h | --help
                 display help and exit
       -v | --version
                 output version information and exit