List your PC’s devices from the terminal …

Discover exactly what devices are inside your PC from the Linux terminal. On this occasion, we will tell you what commands to use so that you can list these devices.

Commands to use from the Linux terminal

There are many ways to prepare a recipe, you would even be willing to bet that there are more ways to list the devices that are connected or housed inside your computer Linux So you will have some of them. And that's not all!

Inevitably, there is a lot of overlap in the information you can get from these commands, so why bother describing so many of them?

On the one hand, the variations in content and details make them different enough for some people to prefer one method over another. The output format of a command can lend itself particularly well to a specific use case. And the format of another command can be ideal for grep channeling or other post-processing method.

Installation required from the Linux terminal

Most of these commands are included in your Linux distribution by default. Ubuntu, Fedora and Manjaro were used as a representative sample of distributions of the main branches of the Debian, Red Hat and Arch families.

The three distributions needed to install «procinfo», which is provided by the lsdev command. The lsscsi command also needed to be installed in all three distributions.

To install lsdev and lsscsi, use these commands:

In Ubuntu:

sudo apt-get install procinf
sudo apt-get install lsscsi

Fedora:

sudo dnf install procinfo
sudo dnf install lsscsi

Manjaro:

sudo pacman -Syu procinfo
sudo pacman -Syu lsscsi

Surprisingly, Manjaro, famous for being a basic type of distribution, was the distro that had most of the commands we will see preinstalled.

Ubuntu and Fedora need the hwinfo installation, and Fedora also requires lshwe hdparm installed.

Ubuntu:

sudo apt-get install hwinfo

Fedora:

sudo dnf install hwinfo
sudo dnf install lshw
sudo dnf install hdparm

1.- mount command

The mount command is used to mount file systems. But issuing the command without parameters causes it to list all mounted file systems, as well as the devices on which they are located. Then we can use this as a means to discover those devices.

mount

The mount output may be longer than you expected, especially if you used the snap method to install software. Each time you use snap, acquire another pseudo-file system and these are listed by mount. Of course, these have no physical devices associated with them, so they are only hiding the real image.

If you see a real file system in the list found on a hard drive, we can isolate it with grep.

Hard drives are identified by their name, usually called "sd" followed by a letter that begins with "a" for the first unit, "b" for the second unit and so on. Partitions are identified by adding a 1 for the first partition and 2 for the second partition, and so on.

Then, the first hard drive would be sda, and the first partition on that disk would be called sda1. Hard drives are interconnected through special device files called block files in / dev. And then they are mounted somewhere in the file system tree.

This grep command used to filter the details of any unit that starts with "sd".

mount | grep /dev/sd

The response from mount tells us that drive / dev / sda is mounted on / (the root of the file system tree) and has an ext4 file system. The "rw" indicates that it has been mounted in read-write mode.

2.- lsblk command

The lsblk command lists the block devices, their mount point and other information. Type lsblken a command line:

lsblk

The output shows:

  • Name: the name of the block device
  • Maj: Min: The largest number shows the type of device. The minimum number is the current device number outside the list of devices of that type. 7: 4, for example, means loop device number 4.
  • RM: if the device is removable or not. 0 means no, 1 means yes.
  • The size is the capacity of the device.
  • RM: if the device is read only or not. 0 means no, 1 means yes.
  • Type: the type of device, for example, loop, dir (directory), disk, rom (CD ROM), etc.
  • Mount point: where the device file system is mounted.

To mess up the output and remove the loop devices, we can use the -e (exclude) option and provide the number of the type of devices we want to ignore.

This lsblk command will cause loop (7) and cd room (11) devices to be ignored.

lsblk -e 7,11

The results now only contain the sda ​​hard drive.

3.- df command

The command informs about the capabilities of the unit. In addition to the free and used space.

Type df in the Linux terminal command line and press Enter.

df

The output table shows:

  • File system: the name of this file system.
  • 1K blocks: the number of 1K blocks that are available in this file system.
  • Used: the number of 1K blocks that have been used in this file system.
  • Available: the number of 1K blocks that are not used in this file system.
  • Use%: the amount of space used in this file system as a percentage.
  • File: the name of the file system, if specified on the command line.
  • Mounted on: the mount point of the file system.

To remove unwanted entries from the output, use the – x (exclude) option. This command will prevent the entries of the loop device from being listed.

df -x squashfs

Thus, the compact output is much easier to analyze to obtain important information.

4.- Linux terminal: the fdisk command

The fdisk command is a tool designed to manipulate the disk partition table, but it can also be used to view information. We can use this to our advantage when we are investigating the devices on a computer.

We will use the -l (list) option to list the partition tables. Because the output can be very long, we will channel the output from fdisk through «less». Because fdisk has the potential to alter disk partition tables, we must use sudo.

sudo fdisk -l

By scrolling through less, you can identify the hardware devices. Here is the entry for the sda ​​hard drive, this is a 10 GB physical hard drive.

Now that we know the identity of one of the hardware devices, we can ask fdisk to report only that item in question.

sudo fdisk -l /dev/sda

As you can see, we get an output of considerably reduced length.

5.- Linux terminal: the files / proc

The pseudo-files in / proc can be viewed for system information. The file we will see is / proc / mounts, which will give us information about mounted file systems. We will not use anything other than cat to view the file.

cat /proc/mounts

The list shows the special device file in / dev that is used to interact with the device and the mount point in the file system tree.

6.- lspci command

This Linux terminal command lists all PCI devices on your computer.

lspci

The information provided is:

Slot: the slot in which the PCi device is installed.

Class: the device class.

Supplier name: the name of the manufacturer.

Device Name: the name of the device.

Subsystem: Name of the subsystem provider (if the device has a subsystem).

Subsystem name: if the device has a subsystem.

Revision number: the version number of the device.

Programming interface: if the device provides an lspci output in a terminal window.

7.- lsusb command

This command will list the devices that are connected to the USB ports of your PC, as well as the USB-enabled devices that are integrated into it.

8.- lsdev command

The lsdev command shows information about all the devices installed on your system. At the outset, this command generates a lot of output, so we will channel it with less information.

lsdev | less

As you can see, there are many hardware devices listed in the Linux terminal output.

You have a list of the most used Linux terminal commands

Here are many ways to investigate the devices inside or that are connected to your computer. So, whatever your particular interest in looking for hardware, there will be a method in this list that will allow you to find what you need.