How to view battery information in Linux

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Introduction

How to check your Laptop battery level from Terminal in your Linux system ? In this article, We have added three simple methods which will help you to check Laptop battery status and level in Terminal in any Linux distribution.

(1): Using Upower command:

The first thing you need to do is figure out the battery path. This can be done with the UPower –enumerate (-e) command line flag, which enumerates object paths for devices:

upower -e
  •  To display the battery status using Upower, just run:
upower -i /org/freedesktop/UPower/devices/battery_BAT0

As you see above, my battery is 75% now.

  • Also you can run the following command instead of the previous command
upower -i `upower -e | grep 'BAT'`

 Upower gives you the complete details of the installed battery such as model, vendor name, serial no, state, voltage, time to empty, percentage and icon name.

  • Also you can display the status of the battery using upower command with grep command to filter your results as shown below
upower -i $(upower -e | grep BAT) | grep --color=never -E "state|to\ full|to\ empty|percentage"
  • You can check upower command man page with
man upower

(2): Using cat and find commands together

  • To know the battery capacity with cat command , Just run
cat /sys/class/power_supply/BAT0/capacity

My battery level is 77% as shown above.

  • To know the battery capacity with find and cat commands to display more details , Just run
find /sys/class/power_supply/BAT0/ -type f | xargs -tn1 cat
qadry@rhel-pc:~$ find /sys/class/power_supply/BAT0/ -type f | xargs -tn1 cat
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=11400000
POWER_SUPPLY_VOLTAGE_NOW=11676000
POWER_SUPPLY_CURRENT_NOW=1645000
POWER_SUPPLY_CHARGE_FULL_DESIGN=3909000
POWER_SUPPLY_CHARGE_FULL=3909000
POWER_SUPPLY_CHARGE_NOW=3040000
POWER_SUPPLY_CAPACITY=77
POWER_SUPPLY_CAPACITY_LEVEL=Normal
POWER_SUPPLY_MODEL_NAME=Primary
POWER_SUPPLY_MANUFACTURER=Hewlett-Packard
POWER_SUPPLY_SERIAL_NUMBER=00000 2014/05/02
cat /sys/class/power_supply/BAT0/charge_full_design
3909000
cat /sys/class/power_supply/BAT0/serial_number
00000 2014/05/02
cat /sys/class/power_supply/BAT0/technology
Li-ion
cat /sys/class/power_supply/BAT0/current_now
1645000
cat /sys/class/power_supply/BAT0/charge_now
3040000
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_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/runtime_suspended_time
0
cat /sys/class/power_supply/BAT0/power/control
auto
cat /sys/class/power_supply/BAT0/manufacturer
Hewlett-Packard
cat /sys/class/power_supply/BAT0/type
Battery
cat /sys/class/power_supply/BAT0/charge_full
3909000
cat /sys/class/power_supply/BAT0/capacity
77
cat /sys/class/power_supply/BAT0/cycle_count
0
cat /sys/class/power_supply/BAT0/voltage_now
11676000
cat /sys/class/power_supply/BAT0/status
Discharging
cat /sys/class/power_supply/BAT0/alarm
0
cat /sys/class/power_supply/BAT0/model_name
Primary
cat /sys/class/power_supply/BAT0/voltage_min_design
11400000
cat /sys/class/power_supply/BAT0/capacity_level
Normal
qadry@rhel-pc:~$

(3): Using battery-level-cli Program

Battery level 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

NOTE: If nodejs is not installed in your system, then visit the following Link to install it How to Install Latest NodeJS and NPM in Linux

  • After that install battery-level-cli utility
sudo npm install --global battery-level-cli
  • Display the battery level using the command below
battery-level

Conclusion

That’s it..

In this article, we illustrate a three methods to view battery information in Linux

Thank you

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
MQ-Jr
MQ-Jr
unixcop Admin

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook