# Have fun in Linux command line 02: Get the battery information(Linux Mint)

It's  pretty interesting to get battery information from command line.

What we need first is the files containing the battery information which is stored in

/sys/class/power_supply/BAT0/

so

cd /sys/class/power_supply/BAT0/

And then we should get to know the battery information. We use

cat capacity status

to print the the capacity and the status(charging or discharging) of the battery to the screen.

Last but not least, add some interesting stuff to this tool we created. Just like last line of the script below.

cd /sys/class/power_supply/BAT0/

echo "Battery Information:"

cat capacity status | cowsay -f meow

Save this three lines to a file called "PowerInformation"(or whatever you like), and make it executable

chmod  +x PowerInformation

cp the file to /bin/ (or make a symbolic link to /bin/)

sudo cp PowerInformation /bin/

(You should install cowsay by using sudo apt-get install cowsay first if you don't have it.)

Type PowerInformation to let a cat to tell you your battery information.

You can choose other animal. Use cowsay -l to get the animal list, then change "meow" in the script to you favorite animal.

Pretty cool. Have fun.:-)

[微信] 扫描二维码打赏

[支付宝] 扫描二维码打赏