How to use upower
If we want to check the power remaining on Ubuntu, and we don't want to open the graphical interface to confirm, we can use upower
command.
If you want to see the complete information, you can use the following command to search:
upower -i /org/freedesktop/UPower/devices/battery_BAT0
Output:
native-path: BAT0
vendor: SP1
model: L17M3PB1
serial: 1657
power supply: yes
updated: January 2, 2020 (Thursday) 15:49:51 (32 seconds ago)
has history: yes
has statistics: yes
battery
present: yes
rechargeable: yes
state: discharging
warning-level: none
energy: 21.56 Wh
energy-empty: 0 Wh
energy-full: 35.93 Wh
energy-full-design: 45 Wh
energy-rate: 20.75 W
voltage: 11.008 V
time to empty: 1.0 hours
percentage: 61%
capacity: 77.3111%
technology: lithium-polymer
icon-name: 'battery-full-symbolic'
History (charge):
1577951391 61.000 discharging
History (rate):
1577951391 20.750 discharging
If we only want to check the remaining battery capacity, we don't actually need to display so much other information.
upower -i $(upower -e | grep BAT) | grep --color=never -E "state|to\ full|to\ empty|percentage"
Output:
state: discharging
time to empty: 1.0 hours
percentage: 56%
It can be seen that my battery is not charging now, and there is only one hour left from no electricity, and the capacity is about 56%.