CentOS 8 is a Linux distribution in which GUI users can check the battery status by pointing the mouse at the battery icon in the status bar. Whereas, the command-line users have to write commands to check the status of the battery. Although, it is not difficult to check battery status on Linux distributions. But, for most beginners, it can look like a demanding task.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related System queries on CentOS Linux Systems.
In this context, we shall look into different methods of checking laptop battery status on CentOS 8.
There are different methods to check battery status on a CentOS machine. Here, you will learn the commands which will help you to check battery status on CentOS 8.
You can use the Upower command to check the battery status. In most Linux distributions, this command is preinstalled. Open the terminal and execute the below-mentioned command:
$ upower -i /org/freedesktop/UPower/devices/battery_BAT0
You will see from the output of the above command which does not only show battery status but also detailed information about the battery such as vendor name, voltage, serial number, and so on.
When you only want to see battery status without detailed information, use the Upower command in combination with the grep command as follows:
$ upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -i "state\|percentage\|time to empty"
From the output of this command, it displays only the battery charging status.
For more details about the Upower command, visit the man pages:
$ man upower
The 'Cat' and 'Find' commands are another easy method to check battery status using the sysfs file system.
Using the sysfs file system, user can easily display the battery charging status by using the following command:
$ cat /sys/class/power_supply/BAT0/capacity
If you also want to see details of the power supply, you can use the ‘Find’ command. Run the following command on your terminal:
$ find /sys/class/power_supply/BAT0/ -type f | xargs -tn1 cat
You will see that the "Find" command displays different details of the battery such as design, model name, manufacturer, etc.
To check the laptop battery status, go into the system setting and choose the 'power' option from the left sidebar.
Here you will see the battery status of your laptop.
This article covers different methods for checking the battery status on CentOS 8. The battery status and ACPI https://en.wikipedia.org/wiki/Advanced_Configuration_and_Power_Interface information is stored in /proc and /sys directory. Using "upower" command or "acpi" command you can get this information.
upower is a command line tool which provides an interface to enumerate power sources on the system. Execute below command in the terminal.
The upower command will show detailed information about the battery:
$ upower -i /org/freedesktop/UPower/devices/battery_BAT1