Checking laptop's battery state in a terminal [duplicate]

Solution 1:

The below command outputs a lot status and statistical information about the battery. The /org/... path can be found with the command upower -e (--enumerate).

upower -i /org/freedesktop/UPower/devices/battery_BAT0

Example output:

  native-path:          /sys/devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0
  vendor:               NOTEBOOK
  model:                BAT
  serial:               0001
  power supply:         yes
  updated:              Thu Feb  9 18:42:15 2012 (1 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               charging
    energy:              22.3998 Wh
    energy-empty:        0 Wh
    energy-full:         52.6473 Wh
    energy-full-design:  62.16 Wh
    energy-rate:         31.6905 W
    voltage:             12.191 V
    time to full:        57.3 minutes
    percentage:          42.5469%
    capacity:            84.6964%
    technology:          lithium-ion
  History (charge):
    1328809335  42.547  charging
    1328809305  42.020  charging
    1328809275  41.472  charging
    1328809245  41.008  charging
  History (rate):
    1328809335  31.691  charging
    1328809305  32.323  charging
    1328809275  33.133  charging

You could use tools like grep to get just the information you want from all that output.

One simple way: piping the above command into

grep -E "state|to\ full|percentage"

outputs:

state:               charging
time to full:        57.3 minutes
percentage:          42.5469%

If you would often like to run that command, then you could make a Bash alias for the whole command. Example:

alias bat='upower -i /org/freedesktop/UPower/devices/battery_BAT0| grep -E "state|to\ full|percentage"'

Add that to the end of your .bashrc file, and you can type 'bat' any time, in the terminal.

There is also a upower -d (--dump) command that shows information for all available power resources such as laptop batteries, external mice, etc.

Solution 2:

A friendly reminder: since Linux kernel 2.6.24 using /proc to store ACPI info has been discouraged and deprecated.

Now we are encouraged to use -> /sys/class/power_supply/BAT0.

UPDATE: Linux 3.19 and onwards, we should look at the following directory -> /sys/class/power_supply/BAT1/

For example, checking capacity & status running

Linux 4.20

# uname -a
Linux netbook 4.20.1-arch1-1-ARCH #1 SMP PREEMPT Wed Jan 9 20:25:43 UTC 2019 x86_64 GNU/Linux
# cat /sys/class/power_supply/BAT1/capacity
99
# cat /sys/class/power_supply/BAT1/status
Charging

and

Linux 5.9

# uname -a
Linux netbook 5.9.1-arch1-1 #1 SMP PREEMPT Sat, 17 Oct 2020 13:30:37 +0000 x86_64 GNU/Linux
# cat /sys/class/power_supply/BAT1/capacity
100
# cat /sys/class/power_supply/BAT1/status
Full

Solution 3:

DEPRECATED - thanks @morhook


First install acpi by running this command,

sudo apt-get install acpi

Then run:

acpi

Sample output:

Battery 0: Discharging, 61%, 01:10:12 remaining

Or for a more verbose output that constantly updates:

watch --interval=5 acpi -V

Output:

Every 5.0s: acpi -V                                     Wed Jan  8 15:45:35 2014

Battery 0: Full, 100%
Adapter 0: on-line
Thermal 0: ok, 44.0 degrees C
Thermal 0: trip point 0 switches to mode critical at temperature 127.0 degrees C
Thermal 0: trip point 1 switches to mode hot at temperature 127.0 degrees C
Cooling 0: intel_powerclamp no state information available
Cooling 1: pkg-temp-0 no state information available
Cooling 2: LCD 100 of 100
Cooling 3: LCD 100 of 100
Cooling 4: Processor 0 of 10
Cooling 5: Processor 0 of 10
Cooling 6: Processor 0 of 10
Cooling 7: Processor 0 of 10
Cooling 8: Processor 0 of 10
Cooling 9: Processor 0 of 10
Cooling 10: Processor 0 of 10
Cooling 11: Processor 0 of 10

Solution 4:

Thanks to @Wilf this works on my Ubuntu 17.10 on Lenovo Yoga 720:

upower -i $(upower -e | grep '/battery') | grep --color=never -E "state|to\ full|to\ empty|percentage"

Output:

state:               fully-charged
percentage:          100%

Or just the numeric value with this one liner

upower -i $(upower -e | grep '/battery') | grep --color=never -E percentage|xargs|cut -d' ' -f2|sed s/%//