- How To Check Laptop Battery Status And Level In Terminal In Linux
- Check Laptop battery status and level from commandline in Linux
- Method 1 — Using «Upower» command
- Method 2 — Using «acpi» command
- Method 3: Using «cat» and «find» commands
- Method 4: Using «Batstat» Program
- Method 5: Using «battery-level-cli» Program
- Conclusion
- How to check battery status and information in Linux
- Steps to show detailed battery information in Linux:
How To Check Laptop Battery Status And Level In Terminal In Linux
Finding your Laptop battery status in GUI mode is easy. You could easily tell the battery level by hovering the mouse pointer over the battery indicator icon in the task/top bar. But, how about from the command line? Not everyone know this. The other day a friend of mine asked how to check his Laptop battery level from Terminal in his Ubuntu desktop — hence this post. Here I have included five simple methods which will help you to check Laptop battery status and level in Terminal in any Linux distribution.
Check Laptop battery status and level from commandline in Linux
We can find the Laptop battery status from command line in multiple methods. Here are a few ways.
Method 1 — Using «Upower» command
The Upower command comes preinstalled with most Linux distributions. To display the battery status using Upower, open up the Terminal and run:
$ upower -i /org/freedesktop/UPower/devices/battery_BAT0
Sample output:
native-path: BAT0 vendor: Samsung SDI model: DELL 7XFJJA2 serial: 4448 power supply: yes updated: Tuesday 01 October 2019 12:50:41 PM IST (101 seconds ago) has history: yes has statistics: yes battery present: yes rechargeable: yes state: fully-charged warning-level: none energy: 33.4443 Wh energy-empty: 0 Wh energy-full: 33.4443 Wh energy-full-design: 48.84 Wh energy-rate: 0.0111 W voltage: 12.446 V percentage: 100% capacity: 68.4773% technology: lithium-ion icon-name: 'battery-full-charged-symbolic'
As you see above, my battery is fully-charged now and the battery level is 100%.
If the above command doesn’t work for any reason, try the following command instead:
$ upower -i `upower -e | grep 'BAT'`
Sample output:
native-path: BAT0 vendor: Samsung SDI model: DELL 7XFJJA2 serial: 4448 power supply: yes updated: Tuesday 01 October 2019 12:54:41 PM IST (48 seconds ago) has history: yes has statistics: yes battery present: yes rechargeable: yes state: fully-charged warning-level: none energy: 33.4443 Wh energy-empty: 0 Wh energy-full: 33.4443 Wh energy-full-design: 48.84 Wh energy-rate: 0.0111 W voltage: 12.446 V percentage: 100% capacity: 68.4773% technology: lithium-ion icon-name: 'battery-full-charged-symbolic'
Upower not just display the battery status, but also the complete details of the installed battery such as model, vendor name, serial no, state, voltage etc.
You can also display the status of the battery only by with combination of upower and grep commands as shown below.
$ upower -i $(upower -e | grep BAT) | grep --color=never -E "state|to\ full|to\ empty|percentage"
Sample output:
state: fully-charged percentage: 100
As you see in the above output, my Laptop battery has been fully charged.
For more details, refer man pages.
Method 2 — Using «acpi» command
The acpi command shows battery status and other ACPI information in your Linux distribution.
You might need to install acpi command in some Linux distributions.
On Arch Linux and its derivatives:
To install acpi on Debian, Ubuntu and its derivatives:
Once acpi installed, run the following command:
Note: Here, «V» is capital letter.
Sample output:
Battery 0: Discharging, 98%, 01:43:14 remaining Battery 0: design capacity 4400 mAh, last full capacity 3013 mAh = 68% Battery 1: Discharging, 0%, rate information unavailable Adapter 0: off-line Thermal 0: ok, 60.5 degrees C Thermal 0: trip point 0 switches to mode critical at temperature 84.0 degrees C Cooling 0: Processor 0 of 3 Cooling 1: intel_powerclamp no state information available Cooling 2: Processor 0 of 3 Cooling 3: x86_pkg_temp no state information available Cooling 4: Processor 0 of 3 Cooling 5: LCD 0 of 15 Cooling 6: Processor 0 of 3
To check only the state of the charge of battery. To do so, run:
Sample output:
Battery 0: Discharging, 98%, 01:48:14 remaining Battery 1: Discharging, 0%, rate information unavailable
Check the battery temperature:
Sample output:
Thermal 0: ok, 58.5 degrees C
We can view the above output in Fahrenheit using -f flag:
Sample output:
Thermal 0: ok, 144.5 degrees F
Want to know whether the AC power is connected or not? Simple! Simply run the following command:
Sample output:
If the AC power is not available, you would the see the following output:
For more details, check the man pages.
Method 3: Using «cat» and «find» commands
This was suggested by one of our reader in the comment section.
We can use cat and find command to display the battery details.
To know only the battery capacity, run:
$ cat /sys/class/power_supply/BAT0/capacity
Sample output:
Here, my battery level is 89%.
For all details about the battery, the command would be:
$ find /sys/class/power_supply/BAT0/ -type f | xargs -tn1 cat
Sample output:
cat /sys/class/power_supply/BAT0/uevent POWER_SUPPLY_NAME=BAT0 POWER_SUPPLY_STATUS=Discharging POWER_SUPPLY_PRESENT=1 POWER_SUPPLY_TECHNOLOGY=Li-ion POWER_SUPPLY_CYCLE_COUNT=0 POWER_SUPPLY_VOLTAGE_MIN_DESIGN=11100000 POWER_SUPPLY_VOLTAGE_NOW=11646000 POWER_SUPPLY_CURRENT_NOW=1905000 POWER_SUPPLY_CHARGE_FULL_DESIGN=4400000 POWER_SUPPLY_CHARGE_FULL=3013000 POWER_SUPPLY_CHARGE_NOW=2696000 POWER_SUPPLY_CAPACITY=89 POWER_SUPPLY_CAPACITY_LEVEL=Normal POWER_SUPPLY_MODEL_NAME=DELL 7XFJJA2 POWER_SUPPLY_MANUFACTURER=Samsung SDI POWER_SUPPLY_SERIAL_NUMBER= 4448 cat /sys/class/power_supply/BAT0/charge_full_design 4400000 cat /sys/class/power_supply/BAT0/serial_number 4448 cat /sys/class/power_supply/BAT0/technology Li-ion cat /sys/class/power_supply/BAT0/current_now 1905000 cat /sys/class/power_supply/BAT0/charge_now 2696000 cat /sys/class/power_supply/BAT0/present 1 cat /sys/class/power_supply/BAT0/power/runtime_active_time 0 cat /sys/class/power_supply/BAT0/power/runtime_active_kids 0 cat /sys/class/power_supply/BAT0/power/runtime_usage 0 cat /sys/class/power_supply/BAT0/power/runtime_status unsupported cat /sys/class/power_supply/BAT0/power/autosuspend_delay_ms cat: /sys/class/power_supply/BAT0/power/autosuspend_delay_ms: Input/output error cat /sys/class/power_supply/BAT0/power/async disabled cat /sys/class/power_supply/BAT0/power/runtime_suspended_time 0 cat /sys/class/power_supply/BAT0/power/runtime_enabled disabled cat /sys/class/power_supply/BAT0/power/control auto cat /sys/class/power_supply/BAT0/manufacturer Samsung SDI cat /sys/class/power_supply/BAT0/type Battery cat /sys/class/power_supply/BAT0/charge_full 3013000 cat /sys/class/power_supply/BAT0/capacity 89 cat /sys/class/power_supply/BAT0/cycle_count 0 cat /sys/class/power_supply/BAT0/voltage_now 11646000 cat /sys/class/power_supply/BAT0/status Discharging cat /sys/class/power_supply/BAT0/alarm 0 cat /sys/class/power_supply/BAT0/model_name DELL 7XFJJA2 cat /sys/class/power_supply/BAT0/voltage_min_design 11100000 cat /sys/class/power_supply/BAT0/capacity_level Normal
Method 4: Using «Batstat» Program
The batstat is a small ncurses-based CLI utility to display your Laptop battery status in Unix-like systems. It will display the following details:
- Current battery level
- Current Energy
- Full charge energy
- Time elapsed from the start of the program, without tracking the sleep time of the machine.
- Battery level history
Installing batstat is a piece of cake.
Git clone the latest version using command:
$ git clone https://github.com/Juve45/batstat.git
The above command will pull the latest batstat version and save its contents in a folder named «batstat».
Cd into batstat/bin/ directory:
Copy «batstat» binary file to your PATH, for example /usr/local/bin/ .
$ sudo cp batstat /usr/local/bin/
Make it executable using command:
$ sudo chmod +x /usr/local/bin/batstat
Finally, run the following command to view your battery status.
As you see in the above screenshot, my battery is in charging mode.
This utility has some limitations though. As of writing this guide, batstat will support only one battery. And, it gathers information only from this folder — «/sys/class/power_supply/» . If your machine contains the battery information on a different folder, this program will not work.
For more details, check batstat github page.
Method 5: Using «battery-level-cli» Program
The battery-level-cli is yet another command line utility to display the battery level in Linux. Unlike the «batstat» program, it will only display the battery level. It won’t help you to find whether the battery is charging or not. It is written in NodeJS, so make sure your system has NodeJS installed. If nodejs is not installed, refer the following to know how to install it.
Once NodeJS installed, tun the following command to install «battery-level-cli» utility:
$ npm install --global battery-level-cli
Now, you can view the battery level using command:
$ battery-level 100%
For more details, check the project’s GitHub repository:
Conclusion
There might be many commands and programs out there to check the laptop battery status from Terminal in Linux. As far as I know, the above given methods have worked just fine as expected. If you know some other commands/utilities to find out the battery status, let me know in the comment section below. I will check and add them as well.
sk
Senthilkumar Palani (aka SK) is the Founder and Editor in chief of OSTechNix. He is a Linux/Unix enthusiast and FOSS supporter. He lives in Tamilnadu, India.
How to check battery status and information in Linux
Linux operating systems utilize the Advanced Configuration and Power Interface (ACPI) daemon to deliver essential battery information. This feature is available in most Linux distributions, ensuring users can easily access battery-related data. The battery information is stored within the /sys filesystem, a location that can be navigated from the command line, or you can use dedicated tools such as acpi and upower.
By accessing the /sys filesystem, or by using command-line tools such as upower or acpi, you can quickly and efficiently view your battery information in Linux.
Steps to show detailed battery information in Linux:
$ ls /sys/class/power_supply/BAT0/ alarm charge_full_design device present technology voltage_now capacity charge_now manufacturer serial_number type capacity_level current_now model_name status uevent charge_full cycle_count power subsystem voltage_min_design
$ cat /sys/class/power_supply/BAT0/capacity 100
$ upower -i /org/freedesktop/UPower/devices/battery_BAT0 native-path: BAT0 vendor: Samsung SDI model: DELL TXF9M6C serial: 34075 power supply: yes updated: Fri 05 Jul 2019 11:27:48 AM +08 (91 seconds ago) has history: yes has statistics: yes battery present: yes rechargeable: yes state: fully-charged warning-level: none energy: 54.0968 Wh energy-empty: 0 Wh energy-full: 54.0968 Wh energy-full-design: 61.9932 Wh energy-rate: 0 W voltage: 8.504 V percentage: 100% capacity: 87.2625% technology: lithium-polymer icon-name: 'battery-full-charged-symbolic'
$ sudo apt update && sudo apt install --assume-yes acpi #Ubuntu and Debian
$ acpi --battery --details Battery 0: Full, 100% Battery 0: design capacity 8157 mAh, last full capacity 7118 mAh = 87%