Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I would like a command that check the battery status through the terminal

"acpi" does not work for 11.10.

share|improve this question
add comment

5 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.

share|improve this answer
1  
upower --enumerate can be useful if you are not sure how to use upower. –  landroni Feb 19 at 21:50
    
@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 at 8:57
    
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 at 9:50
    
@landroni Good point, I have updated the answer. Feel free to edit it if you have more related additions. –  Lekensteyn Feb 20 at 23:41
    
Your edits look great. Thanks. –  landroni Feb 21 at 7:19
add comment

A friendly reminder: since 2.6.24 using /proc to store ACPI info has been discouraged and deprecated. Now it is in /sys/class/power_supply/BAT0.

share|improve this answer
add comment

Maybe you can try:

cat /proc/acpi/battery/BAT0/state

cat /proc/acpi/battery/BAT0/info

share|improve this answer
7  
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 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)

share|improve this answer
    
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
    
So, just curious, can you paste the output of ls /proc/acpi/ ? Thanks –  Matt Oct 20 '11 at 15:41
add comment

First install acpi by running this command,

sudo apt-get install acpi

Then run,

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.