如何從 Linux 終端檢查筆記本電腦電池狀態

如果你像我一樣太極客,想要從命令行檢查電池狀態怎麼辦。 我們可以很容易地從 GUI 獲取電池狀態,但是如果我們想要從命令行獲取所有與電池相關的信息怎麼辦。 聽起來不錯? 好的,我們將在本文中看到兩個 Linux 命令來查找電池相關信息。

電池狀態和 ACPI 信息存儲在 /proc 和 /sys 目錄中。 使用“upower”命令或“acpi”命令可以獲取這些信息。

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 2017 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 命令

阿皮 命令顯示來自 /proc 和 /sys 目錄和電池狀態的有關 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

您可以通過執行以下命令來檢查電池溫度。 要在華氏度中查看,請在末尾附加“-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

這就是本文。 我們已經介紹了兩個檢查電池狀態的命令,這兩個命令都足以檢查各種電池相關信息,如果您知道或遇到其他命令或工具,請在評論部分分享並幫助社區。