cat /sys/class/power_supply/BAT0/capacity - Shows your current battery percentage
cat /sys/class/net/w*/operstate - Shows if your wifi is connected (shows up if connected and down when not)
cat /sys/class/net/e*/operstate - Shows if your ethernet is connected (shows up if connected and down when not)

These are actual files in the linux system that you can open with a file manager and see the output !
There are many more like these in the /sys/class directory. My first reaction when i knew about this was like “Why the hell haven’t i heard about it before ?”. This tip may be useful to general users, but for people who like to do scripting, this can be gold.

Does anyone know where to get more information about the sys/class directory and what all the outputs mean in different cases ?

NOTE: i’m not a linux expert or a professional programmer, but i’m interested in them and learns what i can from online. So i prefer simple solutions that can be easily understood.


I’m not exactly sure what acpi uses, but its probably the most efficient one :

~ >>> time cat /sys/class/power_supply/BAT0/capacity
cat /sys/class/power_supply/BAT0/capacity  0.00s user 0.00s system 3% cpu 0.098 total
~ >>> time acpi
Battery 0: Discharging, 57%, 04:55:40 remaining
acpi  0.00s user 0.01s system 5% cpu 0.105 total

These are very light commands, but i feel like the cat command is more light on resources. acpi might be a better command for general users cause it shows more information about battery. Note that it might not be installed on all systems, so you may have to install it manually. The /sys/class directory is more useful when scripting something cause it works more at a system level and don’t need any extra modules or programs for it to work.

Before i knew about it, i used nmcli -f STATE -t g for checking my wifi connection (on a script), which was way less efficient. The reason why /sys/class method is so nice is cause you don’t need any unnecessary modules or programs just for checking simple system things. These different commands we use maybe doing the same thing on our back.


topng </dev/screen >screenshot.png – Plan 9 took “Everything is a file” to its full potential

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word “Linux” in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

  • 0 users online
  • 47 users / day
  • 71 users / week
  • 134 users / month
  • 430 users / 6 months
  • 3998 subscribers
  • 1302 Posts
  • Modlog