I would like a command that displays the battery status in the terminal.
20 Answers
The below command outputs a lot status and statistical information about the battery. The /org/... path can be found with the command upower -e (--enumerate).
upower -i /org/freedesktop/UPower/devices/battery_BAT0
Example output:
native-path: /sys/devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0
vendor: NOTEBOOK
model: BAT
serial: 0001
power supply: yes
updated: Thu Feb 9 18:42:15 2012 (1 seconds ago)
has history: yes
has statistics: yes
battery
present: yes
rechargeable: yes
state: charging
energy: 22.3998 Wh
energy-empty: 0 Wh
energy-full: 52.6473 Wh
energy-full-design: 62.16 Wh
energy-rate: 31.6905 W
voltage: 12.191 V
time to full: 57.3 minutes
percentage: 42.5469%
capacity: 84.6964%
technology: lithium-ion
History (charge):
1328809335 42.547 charging
1328809305 42.020 charging
1328809275 41.472 charging
1328809245 41.008 charging
History (rate):
1328809335 31.691 charging
1328809305 32.323 charging
1328809275 33.133 charging
You could use tools like grep to get just the information you want from all that output.
One simple way: piping the above command into
grep -E "state|to\ full|percentage"
outputs:
state: charging
time to full: 57.3 minutes
percentage: 42.5469%
If you would often like to run that command, then you could make a Bash alias for the whole command. Example:
alias bat='upower -i /org/freedesktop/UPower/devices/battery_BAT0| grep -E "state|to\ full|percentage"'
Add that to the end of your .bashrc file, and you can type 'bat' any time, in the terminal.
There is also a upower -d (--dump) command that shows information for all available power resources such as laptop batteries, external mice, etc.
- 178,446
A friendly reminder: since Linux kernel 2.6.24 using /proc to store ACPI info has been discouraged and deprecated.
Now we are encouraged to use -> /sys/class/power_supply/BAT0.
UPDATE: Linux 3.19 and onwards, we should look at the following directory -> /sys/class/power_supply/BAT1/
For example, checking capacity & status running
Linux 4.20
# uname -a
Linux netbook 4.20.1-arch1-1-ARCH #1 SMP PREEMPT Wed Jan 9 20:25:43 UTC 2019 x86_64 GNU/Linux
# cat /sys/class/power_supply/BAT1/capacity
99
# cat /sys/class/power_supply/BAT1/status
Charging
and
Linux 5.9
# uname -a
Linux netbook 5.9.1-arch1-1 #1 SMP PREEMPT Sat, 17 Oct 2020 13:30:37 +0000 x86_64 GNU/Linux
# cat /sys/class/power_supply/BAT1/capacity
100
# cat /sys/class/power_supply/BAT1/status
Full
- 10,185
First install acpi by running this command,
sudo apt-get install acpi
Then run:
acpi
Sample output:
Battery 0: Discharging, 61%, 01:10:12 remaining
Or for a more verbose output that constantly updates:
watch --interval=5 acpi -V
Output:
Every 5.0s: acpi -V Wed Jan 8 15:45:35 2014Battery 0: Full, 100% Adapter 0: on-line Thermal 0: ok, 44.0 degrees C Thermal 0: trip point 0 switches to mode critical at temperature 127.0 degrees C Thermal 0: trip point 1 switches to mode hot at temperature 127.0 degrees C Cooling 0: intel_powerclamp no state information available Cooling 1: pkg-temp-0 no state information available Cooling 2: LCD 100 of 100 Cooling 3: LCD 100 of 100 Cooling 4: Processor 0 of 10 Cooling 5: Processor 0 of 10 Cooling 6: Processor 0 of 10 Cooling 7: Processor 0 of 10 Cooling 8: Processor 0 of 10 Cooling 9: Processor 0 of 10 Cooling 10: Processor 0 of 10 Cooling 11: Processor 0 of 10
Thanks to @Wilf this works on my Ubuntu 17.10 on Lenovo Yoga 720:
upower -i $(upower -e | grep '/battery') | grep --color=never -E "state|to\ full|to\ empty|percentage"
Output:
state: fully-charged
percentage: 100%
Or just the numeric value with this one liner
upower -i $(upower -e | grep '/battery') | grep --color=never -E percentage|xargs|cut -d' ' -f2|sed s/%//
- 34,024
- 52
- 172
- 299
It's enough to type the command
acpi
For detailed information you can type
acpi -V
I didn't have to install any packages before.
System: Debian 7.2 64bit
- 3,681
- 331
Here is an article on a package that can check your battery life at the command line.
Basically, all you have to do is:
sudo apt-get install acpi
acpi -V
- 41,732
- 331
Maybe you can try:
cat /proc/acpi/battery/BAT0/state
cat /proc/acpi/battery/BAT0/info
- 13,705
- 700
I'm a little late to the party but here's my little contribution. Based on the previous answers , I have made a simple script batpower:
#!/bin/bash
# Description: Battery charge in percentage
grep POWER_SUPPLY_CAPACITY /sys/class/power_supply/BAT1/uevent
The output for executing this ( ./batpower ) is going to be something like this:
POWER_SUPPLY_CAPACITY=23
N.B. : the batery number may be different for you, in my case it is BAT1, but you can always find it out by cd'ing to /sys/class/power_supply or as Lekensteyn mentioned through upower -e
My machine : Ubuntu 13.10 , 3.11.0
Replace BAT1 in the above bash code to BAT0 if you have older version Ubuntu i.e. 13.04 or later.
IMPROVED SCRIPT: Since my original post, I've made a small improvement to the script:
#!/bin/bash
# Description: Battery charge in percentage
if [ -f /sys/class/power_supply/BAT1/uevent ]
then grep POWER_SUPPLY_CAPACITY /sys/class/power_supply/BAT1/uevent
else echo "Battery isn't present"
fi
As always, pay attention to spaces with bash. This is all self explanatory. If battery is present, it will show up, if not - the script will tell you so. Now, go to your .bashrc file and add $(batpower) to your prompt. Here's mine promt:
PS1='[$(batpower)]\n${debian_chroot:+($debian_chroot)}[*\u@Ubuntu*]:\w\$ '
Update your terminal or open new tab or window, and now you can monitor battery charge constantly in terminal ! including tty ! May the scripting be praised !

- 137
- 107,582
You can either type :
$ acpi -i
Battery 0: Discharging, 98%, 02:51:14 remaining
Battery 0: design capacity 4400 mAh, last full capacity 3733 mAh = 84%
or
$ upower -i $(upower -e | grep BAT)
native-path: BAT0
model: PA5109U-1BRS
serial: FA80
power supply: yes
updated: lun. 07 janv. 2019 03:54:18 CET (24 seconds ago)
has history: yes
has statistics: yes
battery
present: yes
rechargeable: yes
state: discharging
energy: 39,521 Wh
energy-empty: 0 Wh
energy-full: 40,328 Wh
energy-full-design: 47,52 Wh
energy-rate: 13,856 W
voltage: 10,8 V
time to empty: 2,9 hours
percentage: 98%
capacity: 84,8632%
technology: lithium-ion
History (charge):
1546829628 98,000 discharging
1546829593 99,000 discharging
History (rate):
1546829658 13,856 discharging
1546829628 14,752 discharging
1546829597 4,806 discharging
1546829594 2,678 discharging
or with the distrib's inxi package (more up to date from the inxi official source code here)
$ inxi -Bxxx
Battery: ID-1: BAT0 charge: 37.4 Wh condition: 37.4/47.5 Wh (79%) volts: 10.8/10.8 model: PA5109U-1BRS type: Li-ion
serial: FA80 status: Full
- 2,927
- 5
- 35
- 47
You can do it without installing any extra packages:
$ echo $((100*$(sed -n "s/remaining capacity: *\(.*\) m[AW]h/\1/p" /proc/acpi/battery/BAT0/state)/$(sed -n "s/last full capacity: *\(.*\) m[AW]h/\1/p" /proc/acpi/battery/BAT0/info)))%
94%
This command is lifted from byobu's source. It might be a good candidate for a Bash alias.
Run the following command in a terminal for getting detailed info:
cat /proc/acpi/battery/BAT0/info
If you just want the state do:
cat /proc/acpi/battery/BAT0/state
- 178,446
- 11,255
Install acpi, then use watch to continously monitor thru command line.
E.g.
watch --interval=5 acpi -V
will show the information such as below and will update every 5 seconds.
Battery 0: Full, 100%, rate information unavailable
Battery 0: design capacity 6000 mAh, last full capacity 3424 mAh = 57%
Question is why would someone do this? Well, I have a laptop with broken LCD screen that I am now using as my bittorrent box.
- 13,705
- 71
I was going to suggest acpi but after reading it's not working in 11.10, I had an idea.
Please type this in your terminal:
ls /proc/acpi/battery/BAT0 or BAT1
If you get a "file or directory not found" then this isn't going to work.
But, if it lists files, then here's a script [paste it into /usr/games/ or other directory in $PATH, and run sudo chmod +x /usr/games/batterypercent, or whatever you name it] that I just wrote for you that will give you an estimate battery percentage [See below]:
(Note, if not already installed, install the program calc from the repo: sudo apt-get install apcalc)
#!/bin/bash
math() { calc -d "$@"|tr -d ~; }
cd /proc/acpi/battery/BAT0;
max=$(grep 'design capacity:' info|awk '{print $3}')
current=$(grep 'remaining capacity:' state|awk '{print $3}')
percent=$(math "($current / $max) * 100");
echo $(echo $percent|cut -d. -f1)%
I have tested this script on my laptop. I say estimate above because acpi shows 93% battery, and my script shows 90% battery, so try this script against your GUI battery percentage, and see how off it is. In my case, it seems to be consistently 3% lower than acpi's percentage. In that case, you can add this line right before the last line: percent=$((percent + 3)), where "3" is the percentage it's low by.
**In my lenovo, the battery is listed as BAT1, try that too. (12.04 LTS)
You can simple run: upower -i $(upower -e | grep -i BAT)
> upower -i $(upower -e | grep BAT)
native-path: BAT0
vendor: SMP
model: L19M3PF7
serial: 3223
power supply: yes
updated: Sun 05 Mar 2023 02:33:38 PM EET (21 seconds ago)
has history: yes
has statistics: yes
battery
present: yes
rechargeable: yes
state: discharging
warning-level: low
energy: 5.45 Wh
energy-empty: 0 Wh
energy-full: 37.33 Wh
energy-full-design: 45 Wh
energy-rate: 16.219 W
voltage: 10.82 V
charge-cycles: 917
time to empty: 20.1 minutes
percentage: 14%
capacity: 82.9556%
technology: lithium-polymer
icon-name: 'battery-caution-symbolic'
History (charge):
1678019588 14.000 discharging
History (rate):
1678019618 16.219 discharging
1678019588 14.814 discharging
1678019558 13.941 discharging
1678019528 12.350 discharging
Edit: Added -i to grep as battery is sometimes lowercase.
- 445
Similar script without calc or apcalc:
#! /bin/bash
cd /proc/acpi/battery/BAT0;
max=$(grep 'design capacity:' info|awk '{print $3}')
current=$(grep 'remaining capacity:' state|awk '{print $3}')
percent=$(expr $current"00" / $max )
echo -e "Current capacity: \t$current"
echo -e "Max capacity: \t$max"
echo -e "Percent: \t\t$percent"
- 1,060
Here is what I use. It just looks at the diff between full charge and current charge as well as seeing if the charge is dropping in which case it uses notify to alert the user.
#!/bin/bash
#
# experimental battery discharge alerter
#
nsecs=3 # loop sleep time between readings
#
ful=$(cat /sys/class/power_supply/BAT0/energy_full)
#
oldval=0
while true
do
cur=$(cat /sys/class/power_supply/BAT0/energy_now)
dif="$((ful - cur))"
slope="$((cur - oldval))"
if [ "$slope" -lt 0 ]
then
echo "*** discharging!"
notify-send -u critical -i "notification-message-IM" "discharging"
fi
oldval=$cur
sleep $nsecs
done
- 53
This won't help everyone, but it did me - I use byobu whenever I am using a terminal, and battery is one of the options for the status notifications bar.
- 553
Although most of the answers already work, my situation was slightly different. I needed the battery information for ubuntu, windows and mac. On every platform the command is different, so I made an cli app to simplify getting the battery information. The command is:
senzu
outputs for example:
82
It can be found at GitHub: senzu
- 113