linux系统怎么电池电量读取编写程序

2025-11-04 21:27:12

1、打开终端,复制输入如下命令

upower -i $(upower -e | grep 'BAT') | grep -E "state|to\ full|percentage"

linux系统怎么电池电量读取编写程序

2、按下回车,执行命令,就可以看到电池状态了

linux系统怎么电池电量读取编写程序

3、其中

state表示是否在充电,dischraging表示没有连接电源充电,charge表示正在充电

percentage表示电池剩余百分比

4、可以把终端命令写入sh文件,以后调入shell脚本程序,就可以查询电池信息了

echo 'upower -i $(upower -e | grep 'BAT') | grep -E "state|to\ full|percentage"'>battery.sh

linux系统怎么电池电量读取编写程序

5、为battery.sh添加执行权限

chmod +x battery.sh

linux系统怎么电池电量读取编写程序

6、输入

./battery 执行batter.sh脚本

linux系统怎么电池电量读取编写程序

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢