Ubuntu – How to check the battery’s status via the terminal

batterycommand line

I would like a command that displays the battery status in the terminal.

Best Answer

  • 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.