How to List Your Computer’s Devices From the Linux Terminal

Linux PC displaying a shell promptFatmawati Achmad Zaenuri / Shutterstock.com

Find out exactly which devices are connected to your Linux computer. We will cover 12 orders to list your connected devices.

Why 12 orders?

Regardless of the method used to skin a cat, I would be willing to bet that there are more methods to list the devices connected or hosted in your Linux computer. We will show you 12. And that's not all!

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

On the one hand, variations in content and detail make them sufficiently different for some people to prefer one method over another. The output format of an order may very well lend itself to a specific use case. The format of another command may be perfectly suitable for routing via grep, or some other method of further processing.

But above all, it's about making the article as general as possible. Rather than choosing the orders that will interest or use our readership, we would rather provide a large sample of the available orders and let our readers choose which ones they will use and which ones they leave intact.

Some facilities required

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

All three distributions had to install procinfo, which provides the lsdev command. The lsscsi command also had to be installed on all three.

To install lsdev and lsscsi, use these commands.

Ubuntu:

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

sudo apt-get install lsscsi in a terminal window

sudo apt-get install procinf in a terminal window

Felt:

sudo dnf install procinfo
sudo dnf install lsscsi

sudo dnf installs procinfo in a terminal window

sudo dnf installs lsscsi in a terminal window

Manjaro

sudo pacman -Syu procinfo
sudo pacman -Syu lsscsi

sudo pacman -Syu lsscsi in a terminal window

sudo pacman -Syu procinfo in a terminal window

Surprisingly, Manjaro – reputed to be a stripped-down type of distribution – was the distribution that featured most of the controls we will examine pre-installed.

Ubuntu and Fedora needed the installation of hwinfo, and Fedora also installed lshw and hdparm.

Ubuntu:

sudo apt-get install hwinfo

sudo apt-get installs hwinfo in a terminal window

Felt:

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

sudo dnf installs hwinfo in a terminal window

sudo dnf installs hwinfo in a terminal window

sudo dnf installs lshw in a terminal window

1. The mount command

The mount command is used to mount file systems.

However, if the command contains no parameters, it lists all the mounted file systems and the devices on which they are located. So we can use that as a way to discover these devices.

ascend

climb into a terminal window

The output of the timeline may be longer than expected, especially if you used the alignment method to install the software. Each time you use snap, you acquire another pseudo-file system and these are listed by mount. Of course, these are not associated with physical devices, so they hide the whole picture.

mount output in a terminal window "width =" 646 "height =" 382 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror = this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

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

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

So, the first hard drive would be sda, and the first partition on that drive would be called sda1. Hard disks are interfaced through special device files (called block files) in / dev, and then mounted somewhere on the file system tree.

This command used grep to filter the details of any drive starting with "sd".

mount | grep / dev / sd

mount | grep / dev / sd in a terminal window

The output contains the only hard drive of the machine that was used to search for this item.

mount the output in a terminal window "width =" 646 "height =" 97 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror =; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

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

Relatime is the schema used by the file update time routines. The access time is not written to disk unless the modified time (mtime) or the time of modification (ctime) of a file is over. recent than the last hour of access or if the access time (atime) is earlier than a threshold defined by the system. . This greatly reduces the number of disk updates that must be made for frequently viewed files.

The message "errors = remount-ro" indicates that, if there are serious enough errors, the file system will be readonly.

To be able to scroll through the mount output and more easily locate the mounted file systems on devices, direct the output of mount by less.

mount | less

mount | less in a terminal window

Scroll through the output until you see the file systems connected to the special / dev files.

2. The lsblk command

The lsblk command list block devices, their mount point and other information. Type lsblk on a command line:

lsblk

lsblk in a terminal window

The exit shows:

Name: the name of the block device
Shift: Min: The major number indicates the type of device. The minimum number is the number of the current device in the list of devices of this type. 7: 4, for example, means the number 4 loop device.
RM: If the device is removable or not. 0 means no, 1 means yes.
The size is the capacity of the device.
RM: Indicates whether the device is read-only or not. 0 means no, 1 means yes.
Type: type of the device, for example loop, directory (dir), disk, rom (CD-ROM), etc.
Mount Point: The device file system is mounted.

Output of lsblk in a terminal window "width =" 646 "height =" 382 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = "onerror ="; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

To unclutter the output and remove looped devices, we can use the -e (exclude) option and provide the device type number to ignore.

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

lsblk -e 7,11

lsblk -e 7,11 in a terminal window

The results now contain only the hard disk sda.

Output of lsblk in a terminal window "width =" 646 "height =" 132 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror = this.onerror = this = onerror = this; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

3. The df command

The df command reports on disk capacities and used and free space.

Type df on the command line and press Enter.

df

df in a terminal window

The exit chart shows:

Fileystem: The name of this file system.
1K-Blocks: number of 1K blocks available on this file system.
Used: The number of 1K blocks used on this file system.
Available: The number of unused 1K blocks on this file system.
Use%: The amount of space used in this file system as a percentage.
File: The name of the file system, if it is specified on the command line.
Mounted on: The mount point of the file system.

output of df in a terminal window "width =" 646 "height =" 382 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

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

df -x squashfs

df -x squashfs in a terminal window

The compact output is much easier to analyze for important information.

Output df in a terminal window "width =" 646 "height =" 247 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror = this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

4. The fdisk command

The fdisk command is a tool designed to manipulate the disk partition table, but it can be used to see information as well as. We can use this to our advantage when we study the peripherals of a computer.

We will use the -l (list) option to list the partition tables. As the output can be very long, we will send the output of fdisk by less. Since Fdisk can potentially modify disk partition tables, we must use sudo.

sudo fdisk -l

fdisk -l in a terminal window

By scrolling less, you will be able to identify the hardware devices. Here is the entry for the hard drive sda. This is a 10 GB physical hard drive.

output of fdisk in a terminal window "width =" 646 "height =" 382 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

Now that we know the identity of one of the hardware devices, we can ask fdisk to report on that alone.

sudo fdisk -l / dev / sda

sudo fdisk -l / dev / sda in a terminal window

We get an output of greatly reduced length.

output of fdisk in a terminal window "width =" 646 "height =" 247 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

5. The / proc files

The pseudo-files of / proc can be viewed to obtain system information. The file we will be looking at is / proc / mounts, which will give us information about the mounted filesystems. We will not use anything larger than chat to view the file.

cat / proc / mounts

cat / proc / mounts in a terminal window "width =" 646 "height =" 58 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this. onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

The list shows the special device file in / dev used for the interface with the device and the mount point of the file system tree.

output of cat / proc / mounts in a terminal window "width =" 646 "height =" 382 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

We can refine the list using grep to look for entries containing / dev / sd. This will filter the physical disks.

cat / proc / mounts | grep / dev / sd

cat / proc / mounts | grep / dev / sd in a terminal window

This gives us a much more manageable report.

output of cat / proc / mounts in a terminal window "width =" 646 "height =" 97 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

We can be a little more inclusive by using grep to search for devices that contain special device files / dev / sd and / dev / sr. This includes the hard drives and the CD-ROM of this machine.

cat / proc / partitions | grep s[rd]

cat / proc / partitions | grep s[rd] in a terminal window

There are now two devices and one partition included in the output.

output of cat / proc / mounts in a terminal window "width =" 646 "height =" 132 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

6. The lspci command

The lspci command list all PCI devices in your computer.

lspci

lspci in a terminal window

The information provided is:

Slot: The slot in which the PCi device is installed
Class: The class of the device.
Vendor Name: The name of the manufacturer.
Device Name: The name of the device.
Subsystem: The 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: the programming interface, if the device provides one.

Output of lspci in a terminal window "width =" 646 "height =" 382 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror = this" onerror = this; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

7. The lsusb command

The lsusb command will list the devices that are connected to USB ports on your computer as well as USB compatible devices built into your computer.

lsusb

lsusb in a terminal window

This test computer is equipped with a Canon scanner as a USB 5 device and an external USB drive as USB device 4. The devices 3 and 1 are internal USB interface drivers .

USB devices listed in a terminal window "width =" 646 "height =" 167 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

You can receive a more detailed list using the -v (verbose) option, and an even more detailed version by using -vv.

8. The lsdev command

The lsdev command displays information about all installed devices.

This command generates a lot of output, so we'll be running it less.

lsdev | less

lsdev | less in a terminal window

There are many hardware devices listed in the output.

The output lsdev goes through less in a terminal window "width =" 646 "height =" 382 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this. onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

9. The lshw command

The lshw command list devices connected to your computer. This is another command with a lot of output. On the test computer, more than 260 lines of information were generated. We will direct it less once more.

Note that you must use sudo with lshw to get the most out of it. Otherwise, he will not be able to access all devices.

sudo lshw | less

sudo lshw | less in a terminal window

Here is the CD-ROM entry with a SCSI interface. As you can see, the information provided for each device is very detailed. lshw reads most of its information from the various / proc files.

less lshw output in a terminal window "width =" 646 "height =" 382 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this. onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

If you want a shorter and less detailed output, you can use the –short option.

10. The lsscsi command

As you can imagine, the lsscsi command list SCSI devices connected to your computer.

lsscsi

lsscsi in a terminal window

Here are the SCSI devices connected to this test machine.

Output lsscsi in a terminal widnow "width =" 646 "height =" 132 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = "this.onerror"; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

11. The dmidecode command

The dmidecode commands decode the Desktop Management Interface (DMI) tablesand retrieve information about the hardware connected to and inside the computer.

The DMI is also sometimes called SMBIOS (the basic input / output management system), although these are actually two different standards.

Again, we will deliver that less.

dmidecode | less

dmidecode output in a terminal window "width =" 646 "height =" 382 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = "this.onerror =" this.onerror =; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

The dmidecode command can generate reports on more than 40 different types of hardware.

12. The hwinfo command

The hwinfo command is the most detailed of all. When we say you have to bring something with less, it's not optional. On the test computer, it generated 5850 output lines!

You can start slowly by including the –short option.

hwinfo –short

hwinfo --short in a terminal window

If you really need to see the finer details, repeat this operation and omit the –short option.

less hwinfo output in a terminal window "width =" 646 "height =" 382 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this. onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

To wrap up

So here are our dozens of ways to look at the internal devices or connected to your computer.

Whatever your interest in finding this material, there will be a method in this list that will allow you to find what you need.

Advertisements

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.