Baeldung Pro – Linux – NPI EA (cat = Baeldung on Linux)
announcement - icon

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.

Partner – Orkes – NPI EA (tag=Kubernetes)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

1. Overview

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.

2. Using hostnamectl

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.

2.1. With the chassis Option

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.

2.2. With the icon-name Option

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.

3. Using dmidecode

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.

4. Conclusion

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.