
Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: October 2, 2024
Sometimes on Linux, we need an automated way to determine if our computer is a desktop or laptop. For instance, this can be useful for a script that decides which packages to install based on the computer type.
In this tutorial, we’ll look at the Linux commands to check if a computer is a laptop or desktop.
First, we’ll check the hostnamectl command. Then, we’ll learn the dmidecode command.
The quickest way to check the computer type is to use the hostnamectl command. The command comes with the systemd package and should be available by default on most Linux distributions.
There are two ways to check the computer type using the hostnamectl command. Let’s check both.
The first way is to check the computer type using the chassis option:
$ hostnamectl chassis
desktop
As we can see, adding the chassis keyword shows that we use a desktop computer.
Based on the computer type, the other possible outputs of this command are “laptop“, “tablet“, “convertible“, “server“, “handset“, “watch“, “embedded“, and the special chassis types “vm” and “container” for virtualized systems.
However, on some systems, the chassis option may not be available by default. So, let’s check the alternative.
Another way to check the computer type is to use the hostnamectl command with the icon-name option:
$ hostnamectl icon-name
computer-desktop
As a result, it correctly shows that we’re using a desktop computer.
The other possible outputs of this command are “computer-laptop” for the laptop type, and “computer-vm” for the virtual machine type.
The dmidecode command displays the computer hardware information. Let’s use it to display the computer chassis type:
$ sudo dmidecode -s chassis-type
Desktop
As we can see, the computer is of a desktop type.
We need to run the above command with sudo, as otherwise, it lacks the required permissions.
In case we use a laptop, the output of the command may be “Laptop“, “Notebook“, “Portable“, “Hand held” or “Sub Notebook” depending on the manufacturer’s designation.
In this article, we learned the Linux commands to check the type of our computer. First, we looked at the hostnamectl command which provides the chassis and the icon-name options. Then, we discussed the dmidecode command.