brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: upower -i shows battery details on a Linux laptop

Linux
~/tips/tip-hardware-upower-battery-info

upower -i /org/freedesktop/UPower/devices/battery_BAT0

Lists power devices and prints detailed battery information from the command line.

A laptop battery that dies at 60 percent has a story to tell, and Linux will read it to you without a desktop widget. UPower, the daemon behind most battery icons, has a small command line client.

upower -e
upower -i /org/freedesktop/UPower/devices/battery_BAT0

-e (--enumerate) lists the object paths of all power devices. -i (--show-info) takes one of those paths and prints what the daemon knows about it. The battery is often called BAT0, but the name differs per machine, so read it from the first command.

Once you know the pattern, one line does both:

upower -i $(upower -e | grep BAT)

On most laptops the output includes state, percentage and the energy figures, so you can compare the current full capacity with the design capacity and see how worn the cell is. upower -m keeps running and prints a line whenever a power source is added, removed or changed. That is handy when you want to see what plugging in a charger actually triggers.

The caveat: this talks to the UPower daemon, so it needs upower installed and its service running. On a desktop without a battery you only get line power and maybe a UPS, and the grep BAT part returns nothing.

Further reading: upower man page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link