How to check if the computer is a laptop or desktop using command line?


Checking on whether or not the system has a battery is not reliable – a UPS connected to the system may show up as a battery (which showed up when I checked).

So one way is to use dmidecode to get the chassis type of the system:

dmidecode --string chassis-type

But this command requires sudo. To avoid using sudo, you can print the contents of /sys/class/dmi/id/chassis_type, which will return the decimal value of the chassis type.

cat /sys/class/dmi/id/chassis_type

But when I checked, both of the commands gave output where my desktop was considered as “Rack Mount Chassis” (decimal value 23) and my laptop as “Notebook” (decimal value 10). So it might vary according to the system that we are handling.

That’s when I used the hostnamectl command and got better values from the Chassis and Icon name:

hostnamectl status | grep Chassis | cut -f2 -d ":" | tr -d ' '

Since my desktop machine didn’t have any Chassis option, I used the Icon name value:

hostnamectl status | grep "Icon name" | cut -f2 -d ":" | tr -d ' '

So on my laptop the result was “computer-laptop“, on desktop it’s just “computer” and on my server, it is “computer-vm“. You can use these values to install the tlp on the system.



Source link

Leave a Comment