What if you are too geek like me who want to check even battery status from a command line. We can easily get the battery status from GUI, but what if we want all the battery related information from a command line. Sounds interesting? Okay, We will see two Linux commands to find battery related information in this article.
The battery status and ACPI information is stored in /proc and /sys directory. Using "upower" command or "acpi" command you can get this information.
upower command
upower is a command line tool which provides an interface to enumerate power sources on the system. Execute below command in the terminal. You can get "/org/..." path by executing "upower -e". This command will show detailed information about the battery. An output of the command is easily understandable.
$ upower -i /org/freedesktop/UPower/devices/battery_BAT1 native-path: BAT1 vendor: 13-14 model: OA04041 serial: 08726 06/19/2014 power supply: yes updated: Tuesday 15 August 2017 11:41:01 PM IST (23 seconds ago) has history: yes has statistics: yes battery present: yes rechargeable: yes state: discharging energy: 18.7664 Wh energy-empty: 0 Wh energy-full: 32.2048 Wh energy-full-design: 32.2492 Wh energy-rate: 10.0936 W voltage: 14.982 V time to empty: 1.9 hours percentage: 58% capacity: 99.8623% technology: lithium-ion History (charge): 1502820602 58.000 discharging History (rate): 1502820661 10.094 discharging 1502820602 8.895 discharging 1502820572 8.791 discharging
You can use tools like grep to filter out the information you want from all that output. Now, I want to see only important information like stage, time remaining for full charge, current battery level in percentage. So, you can get only that by executing below command.
$upower -i /org/freedesktop/UPower/devices/battery_BAT1|grep -E "state|to\ full|percentage" state: charging time to full: 1.7 hours percentage: 54%
acpi command
acpi command shows infromation about acpi from /proc and /sys directory and battery status. You might have to install acpi on your system.
To Install it, first, update the packages list available in the repositories by executing below command on your system
$ sudo apt-get update
Now, execute the following command to install acpi
sudo apt-get install acpi
Great, Now acpi is installed.
Now, execute a command "acpi -V". It will give you detailed information about the battery.
$ acpi -V Battery 0: Charging, 62%, 00:49:20 until charged Battery 0: design capacity 2116 mAh, last full capacity 2116 mAh = 100% Adapter 0: on-line Thermal 0: ok, 27.8 degrees C Thermal 0: trip point 0 switches to mode hot at temperature 83.0 degrees C Thermal 1: ok, 50.0 degrees C Thermal 1: trip point 0 switches to mode critical at temperature 105.0 degrees C Thermal 1: trip point 1 switches to mode passive at temperature 108.0 degrees C Thermal 2: ok, 50.0 degrees C Thermal 2: trip point 0 switches to mode critical at temperature 105.0 degrees C Thermal 2: trip point 1 switches to mode active at temperature 100.0 degrees C Thermal 2: trip point 2 switches to mode active at temperature 55.0 degrees C Cooling 0: x86_pkg_temp no state information available Cooling 1: intel_powerclamp no state information available Cooling 2: Processor 0 of 10 Cooling 3: Processor 0 of 10 Cooling 4: Processor 0 of 10 Cooling 5: Processor 0 of 10 Cooling 6: Fan 0 of 1
Execute acpi command to see status of battery
$ acpi Battery 0: Charging, 63%, 00:47:24 until charged
You can check battery temperature by executing below command. To see in Fahrenheit append '-f' at end.
$ acpi -t Thermal 0: ok, 44.5 degrees C
If you want to check power adapter is connected or not, execute below command.
$ acpi -a Adapter 0: on-line
acpi has many more options to run with. Just run "man acpi", you will get more options
$man acpi OPTIONS -b | --battery show battery information -a | --ac-adapter show ac adapter information -t | --thermal show thermal information -c | --cooling show cooling device information -V | --everything show every device, overrides above options -s | --show-empty show non-operational devices -i | --details show additional details if available: * battery capacity information * temperature trip points -f | --fahrenheit use fahrenheit as the temperature unit instead of default celsius -k | --kelvin use kelvin as the temperature unit instead of default celsius -p | --proc use the old /proc interface, default is the new /sys one -d | --directory path to ACPI info (either /proc/acpi or /sys/class) -h | --help display help and exit -v | --version output version information and exit
That's it for this article. We have covered two commands to check battery status, Both of these are enough to check various battery related information, If you know or came across some other command or tool, Please share in the comments section and help the community.