Checking your laptop battery from the command line is rather easy using the upower command. This article is an introduction to the Linux upower command and an example from my Linux laptop which is used as a PHP Programming test server.
I have 2 laptops that I use as test servers. They were cheap so I bought one for my wife and one for me. We never really used them so I converted them into PHP programming test servers.
Originally I took the batteries out and stored them away from the computers because we were not using them as portal devices.
Theses computers are probably 4 years old. One battery is dead. Surprisingly the other battery appears to be in like new condition. It has been about 8 months since I changed the good battery and today it is showing 35% charged. It has been setting in my desk drawer.
The local Linux community tells me to keep my battery charged between 30 and 70 percent. They say anything below 30% will add extra wear to the battery as will any charge over 70%.
Currently I do not need the battery, however I may want to load something Like Mint Linux on this computer and use it as a mobile Linux computer. Therefore I would like to keep the battery in good condition and that is why I periodically charge the battery.
Monitoring Laptop Battery Charge
My laptop is running Ubuntu 16.04lts and I had to add the upower package. From the command line it is rather easy – two steps.
sudo apt-get update
sudo apt-get install upower
This morning I put the good battery into my laptop and ran “upower -i” /org/freedesktop/Upower/devices/battery_BAT0 from the command line. Here is the output:
Notice my battery is at 37% change. Amazing!! I was expecting the battery to be dead.
To determine just the state of the battery, time to fully charge, and the percentage of charge, run the following command on the command line.
upower -i $(upower -e | grep BAT) | grep –color=never -E “state|to\ full|to\ empty|percentage”
Here is the output from my laptop:
Since I am only charging my battery to 70%, I expect a much shorter charge time than what a full charge would take. It show it would take 1.7 hours for to fully charge.
Upower Man Page
You can learn more by running “man upower” on the Linux command line. The man page does not give much information, however for my needs, I do not need anything more than is documented in this article.
You may need to install the upower package which is very simple. I provide the command necessary to install the package from the command line on Debian and it’s derivative Linux distributions, such as Ubuntu 16.04lts.
If you need a simple way to monitor your laptop battery from the command line upower may be all you need.