How to obtain a laptop battery information and charging state on Linux

The following linux commands will help you to obtain the information about your laptop battery such as manufacturer, part type, capacity, voltage etc. First, tool which can be used for this job is dmidecode command. If you currently do not have dmidecode available on your Linux system you can install it by:

# apt-get install dmidecode
# yum install dmidecode

next, using dmidecode we can obtain some hardware information about our battery:

# dmidecode -t 22
# dmidecode 2.12
SMBIOS 2.6 present.

Handle 0x002E, DMI type 22, 26 bytes
Portable Battery
        Location: Rear
        Manufacturer: LGC
        Name: 42T4942
        Design Capacity: 93240 mWh
        Design Voltage: 11100 mV
        SBDS Version: 03.01
        Maximum Error: Unknown
        SBDS Serial Number: 073C
        SBDS Manufacture Date: 2012-03-23
        SBDS Chemistry: LION
        OEM-specific Information: 0x00000000

Another and perhaps more useful alternative method to obtain a laptop battery information including its status is by using upower command:

# upower -i `upower -e | grep 'BAT'`
  native-path:          /sys/devices/LNXSYSTM:00/device:00/PNP0A08:00/device:09/PNP0C09:00/PNP0C0A:00/power_supply/BAT0
  vendor:               LGC
  model:                42T4942
  serial:               1852
  power supply:         yes
  updated:              Thu Jul 16 14:23:05 2015 (5 seconds ago)
  has history:          yes
  has statistics:       yes
    present:             yes
    rechargeable:        yes
    state:               charging
    energy:              81.53 Wh
    energy-empty:        0 Wh
    energy-full:         81.53 Wh
    energy-full-design:  93.24 Wh
    energy-rate:         7.22 W
    voltage:             12.848 V
    percentage:          100%
    capacity:            87.441%
    technology:          lithium-ion
  History (rate):
    1437020485  7.477   unknown
    1437020540  7.286   charging

From the above output we can see that the battery is currently charging, it was designed to hold up to 93.24 Wh of power and currently can hold only up to 81.53 Wh which gives it 87.441% of its original capacity left. The above upower command output can also be used to monitor any detail about the battery status. For example using the command below we will monitor its charging status:

# upower --monitor-detail  `upower -e | grep 'BAT'` | grep state
    state:               fully-charged
    state:               discharging