Find out which devices are in or connected to your Linux computer. We discuss 1
Why 12 commands?
As diverse as it is to skin a cat, I would bet that there are more ways to list the devices that exist, connected to or housed in your Linux computer. We show you 12 of them. And that's not all!
The information that you can retrieve from these commands inevitably overlaps strongly. So why bother describing these many commands?
Well, on the one hand, the variations in content and detail make them so different that some people prefer one method over another. The output format of a command may be particularly well suited for a particular application. The format of another command may be ideal for routing through
grep or another method of processing.
First and foremost, however, the article should be made as general as possible. Rather than deciding which commands will be of interest or use to our readership, we'd rather make a broad selection of the available commands available and let our readers choose which ones to use and leave untouched. 19659009] Installation required
Most of these commands are included by default in your Linux distribution. Ubuntu, Fedora, and Manjaro were used as a representative sample of distributions from the main branches of the Debian, Red Hat, and Arch families.
All three distributions were required to install
procinfo which provides the
lsdev command. The command
lsscsi also had to be installed on all three commands.
lsscsi use these commands.
sudo apt-get install lsscsi
sudo dnf install procinfo
sudo dnf install lsscsi
sudo pacman -Syu lsscsi in a terminal window " width="646" height="57" src="/pagespeed_static/1.JiBnMqyl6S.gif" onload="pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);" onerror="this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);"/>
] Surprisingly, Manjaro - famous for its pure distribution - was the distribution that had the bulk of the communication and we'll look preinstalled.
Ubuntu and Fedora had to be installed. 19659006] Ubuntu:sudo apt-get install hwinfo
Fedora:sudo dnf install hwinfosudo dnf install lshw  sudo dnf install hdparm
1 , The mount Command
The mount command is used to mount file systems.
However, if the command is issued without parameters, it lists all mounted file systems and the devices they reside on. So we can use this to discover these devices.mount
The output of
mountmay be longer than expected, especially if you have the
snapmethod to install the software used. Each time you use
snapyou acquire another pseudo-file system and these are listed by
mount. Of course, these are not associated with any physical devices, so they only obscure the actual image.
<img class = "alignnone size-full wp-image-426252" data-pagespeed-lazy-src = "https://www.howtogeek.com/wp-content/uploads/2019/06/xdev_2.png .pagespeed.gp + jp + jw + pj + ws + js + rj + rp + rw + ri + cp + md.ic.t2_svjTLEl.png "alt =" Output from mount 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 If the file system is in the list
Disks are identified by the name, which is usually referred to as "sd", followed by a letter beginning with "a" drive, " b "for the second drive, etc. Partitions are identified by adding a 1 for the first partition and a 2 for the second partition, and so on.
So, the first disk would be sda, and the first partition on this drive would be sda1. Hard disks are connected via special device files (so-called block files) in / dev and then integrated somewhere in the file system tree.
This command used
grepto filter out the details of all drives written with "sd".mount | grep / dev / sd
The output contains the single hard disk of the computer on which this article was researched.
The answer of
mountstates that drive / dev / sda is appended to / (the root of the filesystem tree) and has an ext4 file system. The character "rw" indicates that it was provided in read / write mode. The access time is not written to disk unless the changed time (mtime) or modification time (ctime) of a file is more recent than the last access time, or the access time (atime) is older than a system defined threshold. This significantly reduces the number of disk updates required for frequently accessed files.
The statement "errors = remount-ro" indicates that the file system will be redeployed in read-only mode if there are sufficiently severe errors.  To scroll through the issue of
mountand to more easily recognize the file systems mounted on devices, deduce the issue of
less.mount | less
Scroll through the output until you see file systems connected to / dev special files.
<img class = "alignnone size-full wp-image-426260" data-pagespeed-lazy-src = "https://www.howtogeek.com/wp-content/uploads/2019/06/xdev_6.png .pagespeed.gp + jp + jw + pj + ws + js + rj + rp + rw + ri + cp + md.ic.6h6KRWh6Ei.png "alt =" mount [pipedthroughlessinaterminalwindow"width="646"height="382"src="/pagespeed_static/1JiBnMqyl6Sgif"onload="pagespeedlazyLoadImagesloadIfVisibleAndMaybeBeacon(this);"onerror="thisonerror=null;pagespeedlazyLoadImagesloadIfVisibleA
2nd The lsblk Command
The lsblk command lists the block devices, their mount point, and others Fill in
lsblkin a command line:lsblk
The output shows:
- Name : the name of the block device
Maj: Min : The main number shows the device type, the minimum number is the number of the current device from the list of devices of this type 7: 4 means b For example, loop device number 4.
- RM : Whether the device is removable or not. 0 means no, 1 means yes.
- Size is the capacity of the device.
- RM : Whether the device is write-protected or not. 0 means no, 1 means yes.
- Type : The type of device, eg. Loop, directory, disk, ROM (CD-ROM), etc.
- Mountpoint : Where the file system of the device is mounted.
To disarm the output and remove the loop devices, we can use the
. e [exclude] and specify the number of device types to ignore.
This command causes
lsblk to ignore devices loop (7) and cd room (11).
lsblk -e 7,11
The results now contain only the sda.
<img class = "alignnone size-full wp-image-426271" data-pagespeed-lazy-src = "https://www.howtogeek.com/wp-content/uploads/2019/06/xdev_10.png .pagespeed.gp + jp + jw + pj + ws + js + rj + rp + rw + ri + cp + md.ic.XPcSibPR1b.png "alt =" lsblk output 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.loadIfVisibleAnd900) [TheDefld
The df command specifies the drive capacity and used and free space.
Type in the command line
df and press Enter.
The output table shows:
- File System : The name of this file system.
- 1K Blocks
- : The number of 1K blocks available on this file system.
- Uses : The number of 1K blocks used in this file system.
- Available : The number of 1K blocks that were not used in this file system.
- Usage% : Percentage of disk space used in this file system.
- 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
-x  PossibilityThis command prevents the loop device entries from being
df -x squashfs
 The compact output is much easier to analyze important information. 
. 4 The fdisk Command
fdisk command is a tool for editing the disk partition table, but it can also be used to display information. We can use this to our advantage when we examine the devices in a computer.
We will use the option
-l (list) to list the partition tables. Since the issue may be very long, we derive the issue of
less . Since
fdisk has the potential to change disk partition tables, we must
sudo fdisk -l
] By scrolling through
less you can identify the hardware devices. Here is the entry for the hard disk sda. This is a 10GB physical disk.
Now we can query the identity of one of the hardware devices] fdisk just to report on this point.
sudo fdisk -l / dev / sda
We get an issue of considerably reduced length.
. 5 The / proc files
The pseudo-files in / proc can be displayed to get some system information. The file we are going to look at is / proc / mounts, which gives us some information about the mounted file systems. We will not use anything larger than
cat to display the file.
cat / proc / mounts
<img class = "alignnone size-full wp-image-426292" data-pagespeed-lazy-src = "https://www.howtogeek.com/wp-content/uploads /2019/06/xdev_19.png.pagespeed.gp+jp+jw+pj+ws+js+rj+rp+rw+ri+cp+md.ic.xECk8Kdx9z.png "alt =" 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.loadIfVisibleAndMay] shows the special device file in / dev used to interface to the device and the mount point in the file system tree.
<img class =" alignnone size-full wp -image-426296 "data-pagespeed-lazy-src =" https://www.howtogeek.com/wp-content/uploads/2019/06/xdev_20.png.pagespeed.gp+jp+jw+pj+ws+ js + rj + rp + rw + ri + cp + md.ic.x97Hcve4Gr.png "alt =" output 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; 19659006] We can refine the listing by using
grep to search for entries in / dev / sd. This filters out the physical drives.
cat / proc / mounts | grep / dev / sd
This gives us a much clearer report.
<img class = "alignnone size-full wp-image-426298" data-pagespeed-lazy-src = "https://www.howtogeek.com/wp-content/uploads/2019/06/xdev_22.png .pagespeed.gp + jp + jw + pj + ws + js + rj + rp + rw + ri + cp + md.ic.LwQnNa94WR.png "alt =" 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.loadIfVisibleAndMayLoadImages. "] With
grep lets us search for devices that have special device files for / dev / sd and / dev / sr. This includes hard drives and the CD-ROM for this computer.
cat / proc / partitions | grep s [rd]
The output now contains two devices and one partition.
. 6 The lspci command
lspci lists all PCI devices in your computer.
The information provided is:  Slot : The slot in which the PCi device is installed.
. 7 The lsusb Command
lsusb command lists devices that are connected to your computer's USB ports and USB-enabled devices that are built into your computer.
Connected to this test computer is a Canon scanner as a USB device 5 and an external USB drive as a USB device 4. Devices 3 and 1 are internal USB interface handlers.
You can get a more detailed listing by using the option
-v (verbose) and a more verbose version by using
. vv .
. 8 The lsdev Command
lsdev displays information about all installed devices.
This command generates a lot of output, so we're passing it less.
lsdev | less
There are many hardware devices in the output.
<img class = "alignnone size-full wp-image-426340" data-pagespeed-lazy-src = "https://www.howtogeek.com/wp-content/uploads/2019/06/xdev_30.png .pagespeed.gp + jp + jw + pj + ws + js + rj + rp + rw + ri + cp + md.ic.c3GvDkOazz.png "alt =" lsdev output is passed 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 [199DerBefehllshw The lshw command lists the devices connected to your computer, which is another high-output command, generating over 260 lines of information on the test computer, and redirecting it to
] Note that you need to use
lshw to make the most of it.If you do not, you will not be able to use all devices be accessed.
sudo lshw | less
Here is the entry for the CD-ROM with a SCSI interface. As you can see, the information for each device is very detailed.
lshw Reads most of its information from the various files in /proc.[19659006[19459110[outputoflshwinlessiniterminalwindow"width="646"height="382"src="/pagespeed_static/1JiBnMqyl6Sgif"onload="pagespeedlazyLoadImagesloadIfVisibleAndMaybeBeacon(this);onerror="thisonerror=null;pagespeedlazyLoadImagesloadIfVisibleAndMaybeBeaconForlessdetailedoutputyoucanusetheoption
- short .
10th The lsscsi Command
As you can imagine by now, the
lsscsi command lists the SCSI devices attached to your computer.
Here are the SCSI devices attached to this test computer.
. 11 The dmidecode Command
dmidecode command decodes the Desktop Management Interface (DMI) tables and extracts information about the hardware attached to the computer and the interior of the computer.
The DMI is sometimes referred to as System Management Basic Input / Output System (SMBIOS), although it is actually two different standards.
We redirect this by
dmidecode | less
dmidecode command can report over 40 different types of hardware.
12th The command hwinfo
The command hwinfo is the most detailed of them all. If we say that you need to pass
less this time is not an option. 5850 lines were output on the test computer!
You can start smoothly with the option
- short .
If you really want to see the finest details, repeat this and leave the option
- short gone.
Wrap It Up
Here are our dozen ways to examine or connect devices in your computer.
Whatever your particular interest in hunting for this hardware is, there is a method in this list that will help you figure out what you need.