Baeldung Pro – Linux – NPI EA (cat = Baeldung on Linux)
announcement - icon

Learn through the super-clean Baeldung Pro experience:

>> Membership and Baeldung Pro.

No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.

1. Overview

Power management is a critical aspect of maintaining system health, especially for laptops, long-running servers, and low-powered embedded devices. By understanding the power supply hardware, we can monitor battery health, ensure power source reliability, and troubleshoot power-related issues. To that end, Linux offers various commands and CLI tools that provide detailed information about power status, battery capacity, and AC adapters.

In this tutorial, we’ll discuss various commands and command-line tools to identify power supply hardware information in Linux. Specifically, we’ll be using Ubuntu 24.04 for demonstration purposes.

2. Understanding Power Supply Hardware in Linux

Before we use commands to obtain power supply information, it’s essential to understand what we’re actually looking at. Power supply hardware refers to the components that deliver and monitor power for the system. Linux is designed to interact with these components and exposes their data to the user space through virtual filesystems like sysfs and various CLI tools.

Let’s now talk about the power supply hardware in Linux.

2.1. Battery (BAT0, BAT1, BATn)

Most laptops contain at least one battery. In Linux, each battery is typically named BAT followed by a number, and its information is accessible via tools or the /sys/class/power_supply/ directory.

In practice, we can check the charge level, health, and current status of the battery.

2.2. AC Adapter (AC, AC0, ACn)

The AC adapter serves as the charger or external power source for the system. Linux uses it to determine whether the system is plugged in.

When the adapter is connected, its value is indicated as 1. Conversely, when it’s disconnected, the value shows as 0. This value is found in the online file within the AC adapter directory, e.g., /sys/class/power_supply/AC/online.

2.3. Power Supply Units (PSUs)

On desktops or servers, power comes from PSUs rather than batteries. These may not show up in the same way, but Linux can still detect voltage, current, and energy usage via a sensors interface.

3. Using the /sys/class/power_supply/ Directory

As mentioned earlier, the /sys/class/power_supply/ directory is part of sysfs, a virtual filesystem used by the Linux kernel to expose information about hardware devices. Inside this directory, we can find subdirectories such as AC, BAT0, or battery, depending on the system’s power supply configuration.

As usual, we can discover the subdirectories of the /sys/class/power_supply/ directory using the ls command:

$ ls /sys/class/power_supply/
AC  BAT0

Each of these subdirectories contains files for the different aspects of the respective device:

  • status
  • capacity
  • current_now
  • online

We can use the cat command to display information related to these subdirectories by reading their corresponding files.

For instance, let’s run the cat command to check whether the AC adapter is connected:

$ cat /sys/class/power_supply/AC/online
1

We can also use cat to view the status of the battery:

$ cat /sys/class/power_supply/BAT0/status
Full

Moreover, we can use the grep command to view all available power-related information in one go:

$ grep . /sys/class/power_supply/*/*
grep: /sys/class/power_supply/AC/device: Is a directory
grep: /sys/class/power_supply/AC/hwmon0: Is a directory
/sys/class/power_supply/AC/online:1
…
/sys/class/power_supply/BAT0/voltage_min_design:10000000
/sys/class/power_supply/BAT0/voltage_now:10000000

Evidently, this command recursively displays the contents of all files under each power supply device.

4. Using the inxi Command

inxi is a general-purpose system information tool that also includes basic battery and power details.

We can install inxi from the official repository of the distribution:

$ sudo apt install inxi

Afterward, we can run inxi with the -B flag to obtain the battery-related information:

$ inxi -B
Battery:
  ID-1: BAT0 charge: 46.0 Wh (92.0%) condition: 50.0/50.0 Wh (100.0%)
    volts: 10.0 min: 10.0

As outlined earlier, this output typically includes battery charge percentage, status, capacity, and condition (if a battery is present).

5. Using the upower Command

UPower is a system service that manages power devices like batteries and adapters on Linux. The upower command interacts with this service to display power-related information.

We can install upower on Ubuntu from the official repository or by using the Snap command:

# Snap command
$ sudo snap install upower --beta

# Official repository
$ sudo apt install upower

Next, we list all power devices with:

$ upower -e
/org/freedesktop/UPower/devices/battery_BAT0
/org/freedesktop/UPower/devices/line_power_AC
/org/freedesktop/UPower/devices/DisplayDevice

Moreover, we can use the -i flag to get detailed information about a specific device:

$ upower -i /org/freedesktop/UPower/devices/DisplayDevice
  power supply:         yes
  updated:              Wed 21 May 2025 08:05:18 AM PDT (49 seconds ago)
  has history:          no
  has statistics:       no
  battery
    present:             yes
    state:               discharging
    warning-level:       none
    energy:              43 Wh
    …

UPower is particularly helpful on laptops running GNOME or KDE environments.

6. Using the acpi Command

The acpi tool provides a quick view of the power and thermal status of a given system. It’s lightweight and particularly useful in scripts or on older systems.

Often, we can use the native package manager to install acpi:

$ sudo apt install acpi

Next, let’s run the acpi command with the -b flag to obtain battery information:

$ acpi -b
Battery 0: Discharging, 84%, discharging at zero rate - will never fully discharge.

Moreover, we can use the -c flag to get information about the AC adapter’s status and power supply.

7. Using the powertop Command

powertop is a popular Linux tool that can identify power consumption and management issues. It also offers suggestions on how to extend battery life.

We can install powertop in Ubuntu via the apt command:

$ sudo apt install powertop

After installation, we launch powertop:

$ sudo powertop

As a result, the interface shows real-time power usage, device activity, and tunables that we can adjust for better efficiency:

Output of powertop command to get power supply hardware information in Linux.

powertop is especially useful for extending battery life on laptops or reducing power usage on embedded systems.

8. Using the dmidecode Command

The dmidecode (Desktop Management Interface table decoder) command retrieves system hardware information directly from the system BIOS or UEFI firmware.

To begin with, let’s install dmidecode itself from the official package repository of the distribution:

$ sudo apt install dmidecode

Then, we can use the -t (type) flag with the value 39 to retrieve information about the power supply:

$ sudo dmidecode -t 39

Instead of a numerical value, we can also use keywords like bios and chassis after the -t flag to retrieve specific information.

For instance, using chassis with -t displays chassis-level details, which sometimes include power supply monitoring status:

$ sudo dmidecode -t chassis
# dmidecode 3.3
Getting SMBIOS data from sysfs.
…
	Boot-up State: Safe
	Power Supply State: Safe
	Thermal State: Safe
	Security Status: None

Now that we’ve covered tools for monitoring power supply hardware, let’s look at TLP, a power management tool that optimizes battery life and power consumption.

9. Using tlp for Power Optimization

tlp is a popular Linux power management tool designed to optimize battery life and overall power consumption, especially on laptops. Unlike simple monitoring tools, TLP actively applies power-saving settings in the background based on whether the device is running on battery or AC power.

We can install tlp in Ubuntu by using the apt command:

$ sudo apt install tlp

After installation, we enable tlp as a service using systemd:

$ sudo systemctl enable tlp
Synchronizing state of tlp.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable tlp
Created symlink /etc/systemd/system/multi-user.target.wants/tlp.service → /lib/systemd/system/tlp.service.

Next, let’s start tlp:

$ sudo systemctl start tlp

Finally, we can execute the tlp-stat -s command to get a quick summary of the TLP operational status:

$ tlp-stat -s
--- TLP 1.5.0 --------------------------------------------

+++ System Info
System         = innotek GmbH 1.2 VirtualBox
…
+++ TLP Status
State          = enabled
RDW state      = enabled
Last run       = 09:14:57 AM,     23 sec(s) ago
Mode           = battery
Power source   = battery


$ sudo tlp-stat
--- TLP 1.5.0 --------------------------------------------

+++ Configured Settings:
defaults.conf L0004: TLP_ENABLE="1"
defaults.conf L0005: TLP_WARN_LEVEL="3"
…
+++ TLP Status
State          = enabled
RDW state      = enabled
Last run       = 09:14:57 AM,    102 sec(s) ago
Mode           = battery
Power source   = battery
…
+++ Battery Status: BAT0
/sys/class/power_supply/BAT0/manufacturer                   = innotek
…
Charge                                                      =   45.0 [%]
Capacity                                                    =  100.0 [%]

Thus, the tlp service provides information about the current power settings, battery status, and the active TLP configuration.

10. Conclusion

In this article, we covered numerous command-line tools, including tlp, upower, dmidecode, inxi, and powertop, to check power supply hardware information.

Moreover, we discussed the role of the /sys/class/power_supply/ directory in gaining full visibility into the system’s power supply. Overall, combining these tools enables Linux users to validate power status, investigate power-related issues, and ensure system stability.