How do I check the battery's status via the terminal?
I would like a command that displays the battery status in the terminal.
command-line battery
add a comment |
I would like a command that displays the battery status in the terminal.
command-line battery
29
$ upower -i $(upower -e | grep 'BAT') | grep -E "state|to full|percentage"
– Jake Berger
Dec 4 '14 at 17:23
add a comment |
I would like a command that displays the battery status in the terminal.
command-line battery
I would like a command that displays the battery status in the terminal.
command-line battery
command-line battery
edited Feb 3 at 16:02
Newbyte
54
54
asked Oct 20 '11 at 1:24
JoeJoe
1,4863103
1,4863103
29
$ upower -i $(upower -e | grep 'BAT') | grep -E "state|to full|percentage"
– Jake Berger
Dec 4 '14 at 17:23
add a comment |
29
$ upower -i $(upower -e | grep 'BAT') | grep -E "state|to full|percentage"
– Jake Berger
Dec 4 '14 at 17:23
29
29
$ upower -i $(upower -e | grep 'BAT') | grep -E "state|to full|percentage"– Jake Berger
Dec 4 '14 at 17:23
$ upower -i $(upower -e | grep 'BAT') | grep -E "state|to full|percentage"– Jake Berger
Dec 4 '14 at 17:23
add a comment |
19 Answers
19
active
oldest
votes
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.
9
upower --enumeratecan be useful if you are not sure how to useupower.
– landroni
Feb 19 '14 at 21:50
4
@landroni And the shorthand option isupower -e, that command lists the available paths forupower -i .... If you are lazy and just want a list of all devices, useupower -d(upower --dump).
– Lekensteyn
Feb 20 '14 at 8:57
1
Indeed. I think this would be a useful addition to the answer itself, as when I first tried to useupowerI immediately got lost.
– landroni
Feb 20 '14 at 9:50
1
@landroni Good point, I have updated the answer. Feel free to edit it if you have more related additions.
– Lekensteyn
Feb 20 '14 at 23:41
7
Another one-liner could beupower -i $(upower -e | grep BAT) | grep --color=never -E "state|to full|to empty|percentage"
– Wilf
Jun 6 '14 at 21:27
|
show 1 more comment
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 on Arch Linux 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
Specifically,/sys/class/power_supply/BAT0/capacityseems to show the current charge percentage.
– thomasa88
Aug 6 '18 at 11:09
Deprecated… does it still work?
– neverMind9
Aug 28 '18 at 16:21
1
+1, this should be the accepted answer, since it doesn't rely on extra software that might not be installed and is not needed to answer this question. @neverMind9: I don't know what you mean/procis deprecated but/sysworks perfectly for me, even in kernel 4.20.
– comfreak
Jan 15 at 17:20
1
@comfreak Works for me as well, actually.
– neverMind9
Jan 16 at 1:28
Terry maybe on Arch they start from BAT1 but seems that on Ubuntu always is BAT0, at least nowadays, and AFAIK almost all portable devices uses just one battery (I don't know whyacpi -boracpitool -Boutput three).
– Pablo Bianchi
1 hour ago
add a comment |
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 2014
Battery 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
add a comment |
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/%//
On Fedora 23 I had to grep forbatteryinstead ofBATto make it work. I found that withupower --enumerate.
– erik
Aug 26 '16 at 23:45
grep forbatteryworks in Ubuntu too, so I changed it fromBAT
– rubo77
Feb 7 '18 at 1:11
add a comment |
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
add a comment |
Maybe you can try:
cat /proc/acpi/battery/BAT0/state
cat /proc/acpi/battery/BAT0/info
22
using/procto store ACPI info has been discouraged and deprecated since 2.6.24. Now it's in/sys/class/power_supply/BAT0.
– Terry Wang
Jun 17 '13 at 8:34
add a comment |
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
add a comment |
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 !

You need to check for/sys/class/power_supply/BAT0and/sys/class/power_supply/BAT1... It can be either. And you should use that path (/sys/class/power_supply/BAT#).
– dylnmc
Nov 8 '15 at 16:09
In my Ubuntu 12.04 netbook (after changing to BAT0), I don't seem to get a POWER_SUPPLY_CAPACITY line. It looks like I could calculate it though, from the POWER_SUPPLY_CHARGE_FULL and POWER_SUPPLY_CHARGE_NOW values.
– mwfearnley
Dec 26 '16 at 15:46
add a comment |
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
This has been discouraged in the other identical answer.
– Pablo Bianchi
10 hours ago
add a comment |
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.
+1 from me! CLI FTW. If you have 2 battery's change BAT0 for BAT1 :)
– Rinzwind
Jun 10 '11 at 7:31
Is discourage since 2.6.24, we should use/sys/class/power_supply/BAT0/
– Pablo Bianchi
4 hours ago
add a comment |
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.
add a comment |
This did the job for me in ubuntu 14.04:
cat /sys/class/power_supply/BAT0/capacity
add a comment |
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)
Matt, tried your suggestion, got a "No file or directory"
– Joe
Oct 20 '11 at 13:41
Argh.. okay, I'm almost positive this is whyacpidoesn't work, because I guess 11.10 doesn't support your laptop's ACPI functions as well [battery, etc]. I think I've experienced something like this when upgrading in the past. I'm still on 11.04 though. Sorry that this didn't work for ya :(
– Matt
Oct 20 '11 at 15:36
So, just curious, can you paste the output ofls /proc/acpi/? Thanks
– Matt
Oct 20 '11 at 15:41
add a comment |
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: tt$percent"
add a comment |
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
add a comment |
We can echo just the percentage with that command
upower -i $(upower -e | grep 'BAT') | grep -E "state|to full|percentage" | awk '/perc/{print $2}'
65%
in case you need to extract that value
add a comment |
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.
add a comment |
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
add a comment |
cat /proc/acpi/ac_adapter/AC/state
2
not sure what you're talking about here. running it in the terminal gavecat: /proc/acpi/ac_adapter/AC0/state: No such file or directory
– infoquad
Apr 19 '11 at 12:06
add a comment |
protected by Sergiy Kolodyazhnyy Oct 6 '16 at 5:56
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
19 Answers
19
active
oldest
votes
19 Answers
19
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
9
upower --enumeratecan be useful if you are not sure how to useupower.
– landroni
Feb 19 '14 at 21:50
4
@landroni And the shorthand option isupower -e, that command lists the available paths forupower -i .... If you are lazy and just want a list of all devices, useupower -d(upower --dump).
– Lekensteyn
Feb 20 '14 at 8:57
1
Indeed. I think this would be a useful addition to the answer itself, as when I first tried to useupowerI immediately got lost.
– landroni
Feb 20 '14 at 9:50
1
@landroni Good point, I have updated the answer. Feel free to edit it if you have more related additions.
– Lekensteyn
Feb 20 '14 at 23:41
7
Another one-liner could beupower -i $(upower -e | grep BAT) | grep --color=never -E "state|to full|to empty|percentage"
– Wilf
Jun 6 '14 at 21:27
|
show 1 more comment
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.
9
upower --enumeratecan be useful if you are not sure how to useupower.
– landroni
Feb 19 '14 at 21:50
4
@landroni And the shorthand option isupower -e, that command lists the available paths forupower -i .... If you are lazy and just want a list of all devices, useupower -d(upower --dump).
– Lekensteyn
Feb 20 '14 at 8:57
1
Indeed. I think this would be a useful addition to the answer itself, as when I first tried to useupowerI immediately got lost.
– landroni
Feb 20 '14 at 9:50
1
@landroni Good point, I have updated the answer. Feel free to edit it if you have more related additions.
– Lekensteyn
Feb 20 '14 at 23:41
7
Another one-liner could beupower -i $(upower -e | grep BAT) | grep --color=never -E "state|to full|to empty|percentage"
– Wilf
Jun 6 '14 at 21:27
|
show 1 more comment
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.
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.
edited Feb 20 '14 at 23:40
answered Feb 9 '12 at 17:42
LekensteynLekensteyn
123k49269361
123k49269361
9
upower --enumeratecan be useful if you are not sure how to useupower.
– landroni
Feb 19 '14 at 21:50
4
@landroni And the shorthand option isupower -e, that command lists the available paths forupower -i .... If you are lazy and just want a list of all devices, useupower -d(upower --dump).
– Lekensteyn
Feb 20 '14 at 8:57
1
Indeed. I think this would be a useful addition to the answer itself, as when I first tried to useupowerI immediately got lost.
– landroni
Feb 20 '14 at 9:50
1
@landroni Good point, I have updated the answer. Feel free to edit it if you have more related additions.
– Lekensteyn
Feb 20 '14 at 23:41
7
Another one-liner could beupower -i $(upower -e | grep BAT) | grep --color=never -E "state|to full|to empty|percentage"
– Wilf
Jun 6 '14 at 21:27
|
show 1 more comment
9
upower --enumeratecan be useful if you are not sure how to useupower.
– landroni
Feb 19 '14 at 21:50
4
@landroni And the shorthand option isupower -e, that command lists the available paths forupower -i .... If you are lazy and just want a list of all devices, useupower -d(upower --dump).
– Lekensteyn
Feb 20 '14 at 8:57
1
Indeed. I think this would be a useful addition to the answer itself, as when I first tried to useupowerI immediately got lost.
– landroni
Feb 20 '14 at 9:50
1
@landroni Good point, I have updated the answer. Feel free to edit it if you have more related additions.
– Lekensteyn
Feb 20 '14 at 23:41
7
Another one-liner could beupower -i $(upower -e | grep BAT) | grep --color=never -E "state|to full|to empty|percentage"
– Wilf
Jun 6 '14 at 21:27
9
9
upower --enumerate can be useful if you are not sure how to use upower.– landroni
Feb 19 '14 at 21:50
upower --enumerate can be useful if you are not sure how to use upower.– landroni
Feb 19 '14 at 21:50
4
4
@landroni And the shorthand option is
upower -e, that command lists the available paths for upower -i .... If you are lazy and just want a list of all devices, use upower -d (upower --dump).– Lekensteyn
Feb 20 '14 at 8:57
@landroni And the shorthand option is
upower -e, that command lists the available paths for upower -i .... If you are lazy and just want a list of all devices, use upower -d (upower --dump).– Lekensteyn
Feb 20 '14 at 8:57
1
1
Indeed. I think this would be a useful addition to the answer itself, as when I first tried to use
upower I immediately got lost.– landroni
Feb 20 '14 at 9:50
Indeed. I think this would be a useful addition to the answer itself, as when I first tried to use
upower I immediately got lost.– landroni
Feb 20 '14 at 9:50
1
1
@landroni Good point, I have updated the answer. Feel free to edit it if you have more related additions.
– Lekensteyn
Feb 20 '14 at 23:41
@landroni Good point, I have updated the answer. Feel free to edit it if you have more related additions.
– Lekensteyn
Feb 20 '14 at 23:41
7
7
Another one-liner could be
upower -i $(upower -e | grep BAT) | grep --color=never -E "state|to full|to empty|percentage"– Wilf
Jun 6 '14 at 21:27
Another one-liner could be
upower -i $(upower -e | grep BAT) | grep --color=never -E "state|to full|to empty|percentage"– Wilf
Jun 6 '14 at 21:27
|
show 1 more comment
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 on Arch Linux 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
Specifically,/sys/class/power_supply/BAT0/capacityseems to show the current charge percentage.
– thomasa88
Aug 6 '18 at 11:09
Deprecated… does it still work?
– neverMind9
Aug 28 '18 at 16:21
1
+1, this should be the accepted answer, since it doesn't rely on extra software that might not be installed and is not needed to answer this question. @neverMind9: I don't know what you mean/procis deprecated but/sysworks perfectly for me, even in kernel 4.20.
– comfreak
Jan 15 at 17:20
1
@comfreak Works for me as well, actually.
– neverMind9
Jan 16 at 1:28
Terry maybe on Arch they start from BAT1 but seems that on Ubuntu always is BAT0, at least nowadays, and AFAIK almost all portable devices uses just one battery (I don't know whyacpi -boracpitool -Boutput three).
– Pablo Bianchi
1 hour ago
add a comment |
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 on Arch Linux 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
Specifically,/sys/class/power_supply/BAT0/capacityseems to show the current charge percentage.
– thomasa88
Aug 6 '18 at 11:09
Deprecated… does it still work?
– neverMind9
Aug 28 '18 at 16:21
1
+1, this should be the accepted answer, since it doesn't rely on extra software that might not be installed and is not needed to answer this question. @neverMind9: I don't know what you mean/procis deprecated but/sysworks perfectly for me, even in kernel 4.20.
– comfreak
Jan 15 at 17:20
1
@comfreak Works for me as well, actually.
– neverMind9
Jan 16 at 1:28
Terry maybe on Arch they start from BAT1 but seems that on Ubuntu always is BAT0, at least nowadays, and AFAIK almost all portable devices uses just one battery (I don't know whyacpi -boracpitool -Boutput three).
– Pablo Bianchi
1 hour ago
add a comment |
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 on Arch Linux 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
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 on Arch Linux 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
edited Jan 28 at 6:38
answered Jun 17 '13 at 8:35
Terry WangTerry Wang
6,41932224
6,41932224
Specifically,/sys/class/power_supply/BAT0/capacityseems to show the current charge percentage.
– thomasa88
Aug 6 '18 at 11:09
Deprecated… does it still work?
– neverMind9
Aug 28 '18 at 16:21
1
+1, this should be the accepted answer, since it doesn't rely on extra software that might not be installed and is not needed to answer this question. @neverMind9: I don't know what you mean/procis deprecated but/sysworks perfectly for me, even in kernel 4.20.
– comfreak
Jan 15 at 17:20
1
@comfreak Works for me as well, actually.
– neverMind9
Jan 16 at 1:28
Terry maybe on Arch they start from BAT1 but seems that on Ubuntu always is BAT0, at least nowadays, and AFAIK almost all portable devices uses just one battery (I don't know whyacpi -boracpitool -Boutput three).
– Pablo Bianchi
1 hour ago
add a comment |
Specifically,/sys/class/power_supply/BAT0/capacityseems to show the current charge percentage.
– thomasa88
Aug 6 '18 at 11:09
Deprecated… does it still work?
– neverMind9
Aug 28 '18 at 16:21
1
+1, this should be the accepted answer, since it doesn't rely on extra software that might not be installed and is not needed to answer this question. @neverMind9: I don't know what you mean/procis deprecated but/sysworks perfectly for me, even in kernel 4.20.
– comfreak
Jan 15 at 17:20
1
@comfreak Works for me as well, actually.
– neverMind9
Jan 16 at 1:28
Terry maybe on Arch they start from BAT1 but seems that on Ubuntu always is BAT0, at least nowadays, and AFAIK almost all portable devices uses just one battery (I don't know whyacpi -boracpitool -Boutput three).
– Pablo Bianchi
1 hour ago
Specifically,
/sys/class/power_supply/BAT0/capacity seems to show the current charge percentage.– thomasa88
Aug 6 '18 at 11:09
Specifically,
/sys/class/power_supply/BAT0/capacity seems to show the current charge percentage.– thomasa88
Aug 6 '18 at 11:09
Deprecated… does it still work?
– neverMind9
Aug 28 '18 at 16:21
Deprecated… does it still work?
– neverMind9
Aug 28 '18 at 16:21
1
1
+1, this should be the accepted answer, since it doesn't rely on extra software that might not be installed and is not needed to answer this question. @neverMind9: I don't know what you mean
/proc is deprecated but /sys works perfectly for me, even in kernel 4.20.– comfreak
Jan 15 at 17:20
+1, this should be the accepted answer, since it doesn't rely on extra software that might not be installed and is not needed to answer this question. @neverMind9: I don't know what you mean
/proc is deprecated but /sys works perfectly for me, even in kernel 4.20.– comfreak
Jan 15 at 17:20
1
1
@comfreak Works for me as well, actually.
– neverMind9
Jan 16 at 1:28
@comfreak Works for me as well, actually.
– neverMind9
Jan 16 at 1:28
Terry maybe on Arch they start from BAT1 but seems that on Ubuntu always is BAT0, at least nowadays, and AFAIK almost all portable devices uses just one battery (I don't know why
acpi -b or acpitool -B output three).– Pablo Bianchi
1 hour ago
Terry maybe on Arch they start from BAT1 but seems that on Ubuntu always is BAT0, at least nowadays, and AFAIK almost all portable devices uses just one battery (I don't know why
acpi -b or acpitool -B output three).– Pablo Bianchi
1 hour ago
add a comment |
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 2014
Battery 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
add a comment |
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 2014
Battery 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
add a comment |
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 2014
Battery 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
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 2014
Battery 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
edited Aug 18 '18 at 15:45
answered Nov 24 '12 at 20:20
SuhaibSuhaib
3,28443045
3,28443045
add a comment |
add a comment |
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/%//
On Fedora 23 I had to grep forbatteryinstead ofBATto make it work. I found that withupower --enumerate.
– erik
Aug 26 '16 at 23:45
grep forbatteryworks in Ubuntu too, so I changed it fromBAT
– rubo77
Feb 7 '18 at 1:11
add a comment |
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/%//
On Fedora 23 I had to grep forbatteryinstead ofBATto make it work. I found that withupower --enumerate.
– erik
Aug 26 '16 at 23:45
grep forbatteryworks in Ubuntu too, so I changed it fromBAT
– rubo77
Feb 7 '18 at 1:11
add a comment |
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/%//
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/%//
edited Feb 7 '18 at 1:10
answered Jul 2 '14 at 8:56
rubo77rubo77
15.1k3195201
15.1k3195201
On Fedora 23 I had to grep forbatteryinstead ofBATto make it work. I found that withupower --enumerate.
– erik
Aug 26 '16 at 23:45
grep forbatteryworks in Ubuntu too, so I changed it fromBAT
– rubo77
Feb 7 '18 at 1:11
add a comment |
On Fedora 23 I had to grep forbatteryinstead ofBATto make it work. I found that withupower --enumerate.
– erik
Aug 26 '16 at 23:45
grep forbatteryworks in Ubuntu too, so I changed it fromBAT
– rubo77
Feb 7 '18 at 1:11
On Fedora 23 I had to grep for
battery instead of BAT to make it work. I found that with upower --enumerate.– erik
Aug 26 '16 at 23:45
On Fedora 23 I had to grep for
battery instead of BAT to make it work. I found that with upower --enumerate.– erik
Aug 26 '16 at 23:45
grep for
battery works in Ubuntu too, so I changed it from BAT– rubo77
Feb 7 '18 at 1:11
grep for
battery works in Ubuntu too, so I changed it from BAT– rubo77
Feb 7 '18 at 1:11
add a comment |
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
add a comment |
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
add a comment |
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
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
edited Jul 26 '14 at 15:32
Charo
2,21821226
2,21821226
answered Jul 26 '14 at 14:36
user309404user309404
25132
25132
add a comment |
add a comment |
Maybe you can try:
cat /proc/acpi/battery/BAT0/state
cat /proc/acpi/battery/BAT0/info
22
using/procto store ACPI info has been discouraged and deprecated since 2.6.24. Now it's in/sys/class/power_supply/BAT0.
– Terry Wang
Jun 17 '13 at 8:34
add a comment |
Maybe you can try:
cat /proc/acpi/battery/BAT0/state
cat /proc/acpi/battery/BAT0/info
22
using/procto store ACPI info has been discouraged and deprecated since 2.6.24. Now it's in/sys/class/power_supply/BAT0.
– Terry Wang
Jun 17 '13 at 8:34
add a comment |
Maybe you can try:
cat /proc/acpi/battery/BAT0/state
cat /proc/acpi/battery/BAT0/info
Maybe you can try:
cat /proc/acpi/battery/BAT0/state
cat /proc/acpi/battery/BAT0/info
edited Nov 10 '11 at 19:11
Kris Harper
9,649114771
9,649114771
answered Oct 20 '11 at 5:36
Mariano LMariano L
564138
564138
22
using/procto store ACPI info has been discouraged and deprecated since 2.6.24. Now it's in/sys/class/power_supply/BAT0.
– Terry Wang
Jun 17 '13 at 8:34
add a comment |
22
using/procto store ACPI info has been discouraged and deprecated since 2.6.24. Now it's in/sys/class/power_supply/BAT0.
– Terry Wang
Jun 17 '13 at 8:34
22
22
using
/proc to store ACPI info has been discouraged and deprecated since 2.6.24. Now it's in /sys/class/power_supply/BAT0.– Terry Wang
Jun 17 '13 at 8:34
using
/proc to store ACPI info has been discouraged and deprecated since 2.6.24. Now it's in /sys/class/power_supply/BAT0.– Terry Wang
Jun 17 '13 at 8:34
add a comment |
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
add a comment |
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
add a comment |
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
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
edited Oct 9 '16 at 15:06
jokerdino♦
32.8k21120187
32.8k21120187
answered Jun 10 '11 at 4:57
josh-fugglejosh-fuggle
26114
26114
add a comment |
add a comment |
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 !

You need to check for/sys/class/power_supply/BAT0and/sys/class/power_supply/BAT1... It can be either. And you should use that path (/sys/class/power_supply/BAT#).
– dylnmc
Nov 8 '15 at 16:09
In my Ubuntu 12.04 netbook (after changing to BAT0), I don't seem to get a POWER_SUPPLY_CAPACITY line. It looks like I could calculate it though, from the POWER_SUPPLY_CHARGE_FULL and POWER_SUPPLY_CHARGE_NOW values.
– mwfearnley
Dec 26 '16 at 15:46
add a comment |
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 !

You need to check for/sys/class/power_supply/BAT0and/sys/class/power_supply/BAT1... It can be either. And you should use that path (/sys/class/power_supply/BAT#).
– dylnmc
Nov 8 '15 at 16:09
In my Ubuntu 12.04 netbook (after changing to BAT0), I don't seem to get a POWER_SUPPLY_CAPACITY line. It looks like I could calculate it though, from the POWER_SUPPLY_CHARGE_FULL and POWER_SUPPLY_CHARGE_NOW values.
– mwfearnley
Dec 26 '16 at 15:46
add a comment |
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 !

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 !

edited May 30 '16 at 9:05
Cysioland
1106
1106
answered Jul 23 '14 at 3:23
Sergiy KolodyazhnyySergiy Kolodyazhnyy
73.2k9153317
73.2k9153317
You need to check for/sys/class/power_supply/BAT0and/sys/class/power_supply/BAT1... It can be either. And you should use that path (/sys/class/power_supply/BAT#).
– dylnmc
Nov 8 '15 at 16:09
In my Ubuntu 12.04 netbook (after changing to BAT0), I don't seem to get a POWER_SUPPLY_CAPACITY line. It looks like I could calculate it though, from the POWER_SUPPLY_CHARGE_FULL and POWER_SUPPLY_CHARGE_NOW values.
– mwfearnley
Dec 26 '16 at 15:46
add a comment |
You need to check for/sys/class/power_supply/BAT0and/sys/class/power_supply/BAT1... It can be either. And you should use that path (/sys/class/power_supply/BAT#).
– dylnmc
Nov 8 '15 at 16:09
In my Ubuntu 12.04 netbook (after changing to BAT0), I don't seem to get a POWER_SUPPLY_CAPACITY line. It looks like I could calculate it though, from the POWER_SUPPLY_CHARGE_FULL and POWER_SUPPLY_CHARGE_NOW values.
– mwfearnley
Dec 26 '16 at 15:46
You need to check for
/sys/class/power_supply/BAT0 and /sys/class/power_supply/BAT1 ... It can be either. And you should use that path (/sys/class/power_supply/BAT#).– dylnmc
Nov 8 '15 at 16:09
You need to check for
/sys/class/power_supply/BAT0 and /sys/class/power_supply/BAT1 ... It can be either. And you should use that path (/sys/class/power_supply/BAT#).– dylnmc
Nov 8 '15 at 16:09
In my Ubuntu 12.04 netbook (after changing to BAT0), I don't seem to get a POWER_SUPPLY_CAPACITY line. It looks like I could calculate it though, from the POWER_SUPPLY_CHARGE_FULL and POWER_SUPPLY_CHARGE_NOW values.
– mwfearnley
Dec 26 '16 at 15:46
In my Ubuntu 12.04 netbook (after changing to BAT0), I don't seem to get a POWER_SUPPLY_CAPACITY line. It looks like I could calculate it though, from the POWER_SUPPLY_CHARGE_FULL and POWER_SUPPLY_CHARGE_NOW values.
– mwfearnley
Dec 26 '16 at 15:46
add a comment |
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
This has been discouraged in the other identical answer.
– Pablo Bianchi
10 hours ago
add a comment |
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
This has been discouraged in the other identical answer.
– Pablo Bianchi
10 hours ago
add a comment |
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
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
edited Apr 19 '11 at 14:37
Lekensteyn
123k49269361
123k49269361
answered Apr 19 '11 at 12:20
MEMMEM
4,581113141
4,581113141
This has been discouraged in the other identical answer.
– Pablo Bianchi
10 hours ago
add a comment |
This has been discouraged in the other identical answer.
– Pablo Bianchi
10 hours ago
This has been discouraged in the other identical answer.
– Pablo Bianchi
10 hours ago
This has been discouraged in the other identical answer.
– Pablo Bianchi
10 hours ago
add a comment |
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.
+1 from me! CLI FTW. If you have 2 battery's change BAT0 for BAT1 :)
– Rinzwind
Jun 10 '11 at 7:31
Is discourage since 2.6.24, we should use/sys/class/power_supply/BAT0/
– Pablo Bianchi
4 hours ago
add a comment |
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.
+1 from me! CLI FTW. If you have 2 battery's change BAT0 for BAT1 :)
– Rinzwind
Jun 10 '11 at 7:31
Is discourage since 2.6.24, we should use/sys/class/power_supply/BAT0/
– Pablo Bianchi
4 hours ago
add a comment |
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.
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.
edited Apr 13 '17 at 12:23
Community♦
1
1
answered Jun 10 '11 at 5:35
ændrükændrük
42.1k61195342
42.1k61195342
+1 from me! CLI FTW. If you have 2 battery's change BAT0 for BAT1 :)
– Rinzwind
Jun 10 '11 at 7:31
Is discourage since 2.6.24, we should use/sys/class/power_supply/BAT0/
– Pablo Bianchi
4 hours ago
add a comment |
+1 from me! CLI FTW. If you have 2 battery's change BAT0 for BAT1 :)
– Rinzwind
Jun 10 '11 at 7:31
Is discourage since 2.6.24, we should use/sys/class/power_supply/BAT0/
– Pablo Bianchi
4 hours ago
+1 from me! CLI FTW. If you have 2 battery's change BAT0 for BAT1 :)
– Rinzwind
Jun 10 '11 at 7:31
+1 from me! CLI FTW. If you have 2 battery's change BAT0 for BAT1 :)
– Rinzwind
Jun 10 '11 at 7:31
Is discourage since 2.6.24, we should use
/sys/class/power_supply/BAT0/– Pablo Bianchi
4 hours ago
Is discourage since 2.6.24, we should use
/sys/class/power_supply/BAT0/– Pablo Bianchi
4 hours ago
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Sep 2 '11 at 15:25
Kris Harper
9,649114771
9,649114771
answered Aug 30 '11 at 20:33
iceburniceburn
511
511
add a comment |
add a comment |
This did the job for me in ubuntu 14.04:
cat /sys/class/power_supply/BAT0/capacity
add a comment |
This did the job for me in ubuntu 14.04:
cat /sys/class/power_supply/BAT0/capacity
add a comment |
This did the job for me in ubuntu 14.04:
cat /sys/class/power_supply/BAT0/capacity
This did the job for me in ubuntu 14.04:
cat /sys/class/power_supply/BAT0/capacity
edited Nov 23 '14 at 13:57
s3lph
10.5k94572
10.5k94572
answered Nov 23 '14 at 13:29
the_saintthe_saint
5111
5111
add a comment |
add a comment |
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)
Matt, tried your suggestion, got a "No file or directory"
– Joe
Oct 20 '11 at 13:41
Argh.. okay, I'm almost positive this is whyacpidoesn't work, because I guess 11.10 doesn't support your laptop's ACPI functions as well [battery, etc]. I think I've experienced something like this when upgrading in the past. I'm still on 11.04 though. Sorry that this didn't work for ya :(
– Matt
Oct 20 '11 at 15:36
So, just curious, can you paste the output ofls /proc/acpi/? Thanks
– Matt
Oct 20 '11 at 15:41
add a comment |
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)
Matt, tried your suggestion, got a "No file or directory"
– Joe
Oct 20 '11 at 13:41
Argh.. okay, I'm almost positive this is whyacpidoesn't work, because I guess 11.10 doesn't support your laptop's ACPI functions as well [battery, etc]. I think I've experienced something like this when upgrading in the past. I'm still on 11.04 though. Sorry that this didn't work for ya :(
– Matt
Oct 20 '11 at 15:36
So, just curious, can you paste the output ofls /proc/acpi/? Thanks
– Matt
Oct 20 '11 at 15:41
add a comment |
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)
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)
edited Sep 15 '12 at 17:39
xcorat
1134
1134
answered Oct 20 '11 at 2:42
MattMatt
6,48683550
6,48683550
Matt, tried your suggestion, got a "No file or directory"
– Joe
Oct 20 '11 at 13:41
Argh.. okay, I'm almost positive this is whyacpidoesn't work, because I guess 11.10 doesn't support your laptop's ACPI functions as well [battery, etc]. I think I've experienced something like this when upgrading in the past. I'm still on 11.04 though. Sorry that this didn't work for ya :(
– Matt
Oct 20 '11 at 15:36
So, just curious, can you paste the output ofls /proc/acpi/? Thanks
– Matt
Oct 20 '11 at 15:41
add a comment |
Matt, tried your suggestion, got a "No file or directory"
– Joe
Oct 20 '11 at 13:41
Argh.. okay, I'm almost positive this is whyacpidoesn't work, because I guess 11.10 doesn't support your laptop's ACPI functions as well [battery, etc]. I think I've experienced something like this when upgrading in the past. I'm still on 11.04 though. Sorry that this didn't work for ya :(
– Matt
Oct 20 '11 at 15:36
So, just curious, can you paste the output ofls /proc/acpi/? Thanks
– Matt
Oct 20 '11 at 15:41
Matt, tried your suggestion, got a "No file or directory"
– Joe
Oct 20 '11 at 13:41
Matt, tried your suggestion, got a "No file or directory"
– Joe
Oct 20 '11 at 13:41
Argh.. okay, I'm almost positive this is why
acpi doesn't work, because I guess 11.10 doesn't support your laptop's ACPI functions as well [battery, etc]. I think I've experienced something like this when upgrading in the past. I'm still on 11.04 though. Sorry that this didn't work for ya :(– Matt
Oct 20 '11 at 15:36
Argh.. okay, I'm almost positive this is why
acpi doesn't work, because I guess 11.10 doesn't support your laptop's ACPI functions as well [battery, etc]. I think I've experienced something like this when upgrading in the past. I'm still on 11.04 though. Sorry that this didn't work for ya :(– Matt
Oct 20 '11 at 15:36
So, just curious, can you paste the output of
ls /proc/acpi/ ? Thanks– Matt
Oct 20 '11 at 15:41
So, just curious, can you paste the output of
ls /proc/acpi/ ? Thanks– Matt
Oct 20 '11 at 15:41
add a comment |
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: tt$percent"
add a comment |
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: tt$percent"
add a comment |
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: tt$percent"
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: tt$percent"
answered Nov 15 '14 at 18:24
xerostomusxerostomus
38147
38147
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Feb 28 '16 at 12:47
Mark SimmonsMark Simmons
112
112
add a comment |
add a comment |
We can echo just the percentage with that command
upower -i $(upower -e | grep 'BAT') | grep -E "state|to full|percentage" | awk '/perc/{print $2}'
65%
in case you need to extract that value
add a comment |
We can echo just the percentage with that command
upower -i $(upower -e | grep 'BAT') | grep -E "state|to full|percentage" | awk '/perc/{print $2}'
65%
in case you need to extract that value
add a comment |
We can echo just the percentage with that command
upower -i $(upower -e | grep 'BAT') | grep -E "state|to full|percentage" | awk '/perc/{print $2}'
65%
in case you need to extract that value
We can echo just the percentage with that command
upower -i $(upower -e | grep 'BAT') | grep -E "state|to full|percentage" | awk '/perc/{print $2}'
65%
in case you need to extract that value
answered Mar 25 '18 at 11:56
intikaintika
24016
24016
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Jan 7 '16 at 8:41
sheepeatingtazsheepeatingtaz
35338
35338
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Jan 7 at 2:52
SebMaSebMa
263210
263210
add a comment |
add a comment |
cat /proc/acpi/ac_adapter/AC/state
2
not sure what you're talking about here. running it in the terminal gavecat: /proc/acpi/ac_adapter/AC0/state: No such file or directory
– infoquad
Apr 19 '11 at 12:06
add a comment |
cat /proc/acpi/ac_adapter/AC/state
2
not sure what you're talking about here. running it in the terminal gavecat: /proc/acpi/ac_adapter/AC0/state: No such file or directory
– infoquad
Apr 19 '11 at 12:06
add a comment |
cat /proc/acpi/ac_adapter/AC/state
cat /proc/acpi/ac_adapter/AC/state
edited Dec 16 '12 at 0:58
Eric Carvalho
41.9k17115147
41.9k17115147
answered Apr 19 '11 at 12:03
Todd HarrisTodd Harris
111
111
2
not sure what you're talking about here. running it in the terminal gavecat: /proc/acpi/ac_adapter/AC0/state: No such file or directory
– infoquad
Apr 19 '11 at 12:06
add a comment |
2
not sure what you're talking about here. running it in the terminal gavecat: /proc/acpi/ac_adapter/AC0/state: No such file or directory
– infoquad
Apr 19 '11 at 12:06
2
2
not sure what you're talking about here. running it in the terminal gave
cat: /proc/acpi/ac_adapter/AC0/state: No such file or directory– infoquad
Apr 19 '11 at 12:06
not sure what you're talking about here. running it in the terminal gave
cat: /proc/acpi/ac_adapter/AC0/state: No such file or directory– infoquad
Apr 19 '11 at 12:06
add a comment |
protected by Sergiy Kolodyazhnyy Oct 6 '16 at 5:56
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
29
$ upower -i $(upower -e | grep 'BAT') | grep -E "state|to full|percentage"– Jake Berger
Dec 4 '14 at 17:23