4

There are plenty of tutorials online for checking your battery level in a ubuntu terminal. The most common solution seems to be to use upower. However, when I run upower in a WSL Ubuntu shell in Windows 10 on my Surface Pro, I get this:

user@sp4-2637:~/the_thing$ sudo upower

(upower:665): UPower-WARNING **: Cannot connect to upowerd: Could not connect: No such file or directory

Running with sudo priviliges yields the same result.

On my laptop running native ubuntu I can query the battery level like this;

cat /sys/class/power_supply/BAT0/capacity

However, this results in the following on my Surface:

user@sp4-2637:~$ cat /sys/class/power_supply/BAT0/capacity
cat: /sys/class/power_supply/BAT0/capacity: No such file or directory

How can I query the battery level in a WSL ubuntu shell for a Microsoft Surface?

6

As I wrote this question I found the solution so I thought I'd share it.

I don't know whether this is a peculiarity of the Surface hardware or of the WSL ubuntu version, but the directory structure appears to be different on this setup:

user@sp4-2637:~$ ls /sys/class/power_supply/
ac  battery  usb

Rather than looking in the BAT0 directory I can find the battery level in battery:

user@sp4-2637:~$ cat /sys/class/power_supply/battery/capacity
100
2
  • 1
    I found cat /sys/class/power_supply/battery/capacity to work with WSL on Thinkpad T480 as well. It correctly displays the charges left on both batteries (internal + swappable). – llinfeng Nov 12 '19 at 1:12
  • how to change this? i had this problem too.. my correct path is /sys/class/power_supply/BAT1/capacity – Putra Fajar Hasanuddin May 13 '20 at 22:39
1

My Surface-Book-2 with WSL2 Ubuntu shell has the battery level in /sys/class/power_supply/BAT1/capacity

It may be different depending on hardware. Try the following locations

/sys/class/power_supply/BAT1/capacity
/sys/class/power_supply/BAT0/capacity
/sys/class/power_supply/battery/capacity
-1

If tlp is a package available on WSL Ubuntu shell you can run the command

sudo tlp stat -b
1
  • WSL's kernel doesn't expose ACPI information which tlp requires in order to query the device's battery state, – Rich Turner Dec 16 '20 at 1:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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