Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i check if the platform is laptop or desktop on ubuntu?

What is the most simple way to check if the executing platform is laptop or desktop? If i need to check the files in /sys/class/power_supply/ which file should i go for? Thanks

like image 244
Umut Avatar asked Oct 17 '25 13:10

Umut


2 Answers

What about checking if there is a Lid? This should work with Ubuntu – acpi:

if [ -d "/proc/acpi/button/lid" ]; then
    echo "computer is a laptop"
fi
like image 115
Gabriel Coutinho De Miranda Avatar answered Oct 19 '25 04:10

Gabriel Coutinho De Miranda


You only think you care about distinguishing laptops from desktops. What you really care about is simply whether /sys/class/power_supply/ exists.

if [ -d "/sys/class/power_supply" ]; then
    # Work with the files in /sys/class/power_supply
fi
like image 33
chepner Avatar answered Oct 19 '25 02:10

chepner