Using upower to get battery status from CLI / Linux

If you want to get the battery info form command line here is a way of doing that with the help of upower utility:

Simply use:

upower -d

or to get info for only a specific device, first get the device list:

$ upower -e
 
/org/freedesktop/UPower/devices/line_power_ADP1
/org/freedesktop/UPower/devices/battery_BAT0

Then get the info for the device:

$ upower -i /org/freedesktop/UPower/devices/battery_BAT0
 
  native-path:          /sys/devices/LNXSYSTM:00/device:00/PNP0A08:00/device:02/PNP0C09:00/PNP0C0A:00/power_supply/BAT0
  vendor:               SANYO
  model:                LNV-42T4751
  serial:               490
  power supply:         yes
  updated:              Wed Nov 28 15:16:01 2012 (26 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               discharging
    energy:              35.13 Wh
    energy-empty:        0 Wh
    energy-full:         44.89 Wh
    energy-full-design:  47.52 Wh
    energy-rate:         14.957 W
    voltage:             11.667 V
    time to empty:       2.3 hours
    percentage:          78.258%
    capacity:            94.4655%
    technology:          lithium-ion
  History (charge):
    1354112161  78.258  discharging
    1354112131  78.570  discharging
    1354112101  78.926  discharging
  History (rate):
    1354112161  14.957  discharging
    1354112131  17.688  discharging
    1354112101  18.782  discharging