6/1/2023 0 Comments Battery status![]() Yes, there are some utilities in Linux that can be of help in this regard. But, did you know you can find the battery status through the Linux command line as well? Hovering the mouse cursor over the battery indicator given in the Laptop task bar simply shows the battery level. (12.Checking the battery status through GUI is easy. **In my lenovo, the battery is listed as BAT1, try that too. 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 case, it seems to be consistently 3% lower than acpi's percentage. 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. Max=$(grep 'design capacity:' info|awk '') (Note, if not already installed, install the program calc from the repo: sudo apt-get install apcalc) #!/bin/bash If you get a "file or directory not found" then this isn't going to work.īut, if it lists files, then here's a script that I just wrote for you that will give you an estimate battery percentage : I was going to suggest acpi but after reading it's not working in 11.10, I had an idea. Or with the distrib's inxi package (more up to date from the inxi official source code here) $ inxi -Bxxxīattery: 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 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 !īattery 0: Discharging, 98%, 02:51:14 remainingīattery 0: design capacity 4400 mAh, last full capacity 3733 mAh = 84% bashrc file and add $(batpower) to your prompt. ![]() If battery is present, it will show up, if not - the script will tell you so. Then grep POWER_SUPPLY_CAPACITY /sys/class/power_supply/BAT1/ueventĪs always, pay attention to spaces with bash. IMPROVED SCRIPT: Since my original post, I've made a small improvement to the script: #!/bin/bash Replace BAT1 in the above bash code to BAT0 if you have older version Ubuntu i.e. : 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 batpower ) is going to be something like this: POWER_SUPPLY_CAPACITY=23 Grep POWER_SUPPLY_CAPACITY /sys/class/power_supply/BAT1/uevent # Description: Battery charge in percentage Based on the previous answers, I have made a simple script batpower: #!/bin/bash I'm a little late to the party but here's my little contribution. There is also a upower -d ( -dump) command that shows information for all available power resources such as laptop batteries, external mice, etc. bashrc file, and you can type 'bat' any time, in the terminal. Example: alias bat='upower -i /org/freedesktop/UPower/devices/battery_BAT0| grep -E "state|to\ full|percentage"'Īdd that to the end of your. If you would often like to run that command, then you could make a Bash alias for the whole command. One simple way: piping the above command into grep -E "state|to\ full|percentage" You could use tools like grep to get just the information you want from all that output. upower -i /org/freedesktop/UPower/devices/battery_BAT0Įxample output: native-path: /sys/devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0 path can be found with the command upower -e ( -enumerate). The below command outputs a lot status and statistical information about the battery.
0 Comments
Leave a Reply. |