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. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |