-
List device name of the battery:
upower -e
, I got the name is "/org/freedesktop/UPower/devices/battery_BAT0"; -
Print the status of the battery:
upower -i /org/freedesktop/UPower/devices/battery_BAT0
; -
Only print the charge persent of the battery:
upower -i /org/freedesktop/UPower/devices/battery_BAT0|awk '/^\s*percentage:/ {print $2}'