قالب وردپرس درنا توس
Home / Tips and Tricks / To list your computer's devices through the Linux terminal

To list your computer's devices through the Linux terminal



  Linux PC with shell prompt
Fatmawati Achmad Zaenuri / Shutterstock.com

Find out which devices are in or connected to your Linux computer. We discuss 1

2 commands for listing your connected devices.

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.

To install lsdev and lsscsi use these commands.

Ubuntu: [19659014sudoapt-getinstallprocinf

  sudo apt-get install lsscsi 

  sudo apt-get install lsscsi in a terminal window

 sudo apt-get install procinf in a terminal window

Fedora:

  sudo dnf install procinfo 
  sudo dnf install lsscsi 

  sudo dnf install procinfo in a terminal window

 sudo dnf install lsscsi in a terminal window [Sudopacman-Syulsscsi

  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);"/> 

 sudo pacman -Syu procinfo window

] 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 

  sudo apt-get install hwinfo in a terminal window

Fedora:

  sudo dnf install hwinfo 
  sudo dnf install lshw [19659] sudo dnf install hdparm 

  sudo dnf install hwinfo in a terminal window

 sudo dnf install hwinfo in a terminal window

 sudo dnf install lshw in a terminal window

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 

  mount in a terminal window

The output of mount may be longer than expected, especially if you have the snap method to install the software used. Each time you use snap you 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 grep to filter out the details of all drives written with "sd".

  mount | grep / dev / sd 

  mount | grep / dev / sd in a terminal window

The output contains the single hard disk of the computer on which this article was researched.

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

The answer of mount states 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. [19659006] To scroll through the issue of mount and to more easily recognize the file systems mounted on devices, deduce the issue of mount by less .

  mount | less 

  mount | less in a terminal window

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 lsblk in a command line:

  lsblk 

  lsblk in a terminal window

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.

  lsblk 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 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 

  lsblk -e 7,11 in a terminal window

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.

  df 

  df in a terminal window

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. [19659062] Mounted [19659085] 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); "onerror =" this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

To remove unwanted entries from the output, use -x [1945901] PossibilityThis command prevents the loop device entries from being

  df -x squashfs 

  df -x squashfs in a terminal window [19659006] The compact output is much easier to analyze important information. [19659006]   df output 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 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 fdisk by less . Since fdisk has the potential to change disk partition tables, we must sudo .

  sudo fdisk -l 

  Using fdisk -l in a terminal window

] 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.

 Output from 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 we can query the identity of one of the hardware devices] fdisk just to report on this point.

  sudo fdisk -l / dev / sda 

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

We get an issue of considerably reduced length.

 Output from 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 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 

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

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] 

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

The output now contains two devices and one partition.

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

. 6 The lspci command

The command lspci lists all PCI devices in your computer.

  lspci 

 lspci in a terminal window

The information provided is: [19659068] Slot : The slot in which the PCi device is installed.

  • Class : The class of the device.
  • Manufacturer name : The name of the manufacturer.
  • Device name : The name of the device.
  • Subsystem : Subsystem manufacturer name (if the device has a subsystem).
  • Subsystem name : If the device has a subsystem.
  • Version number : The version number of the device
  • Programming Interface : The programming interface if the device offers one.
  •   lspci output in a terminal window "width =" 646 "height =" 382 "src =" /pagespeed_static/1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this. onerror = zero; pagespeed.lazyLoadImages.loadIfVisi bleAndMaybeBeacon (this);

    . 7 The lsusb Command

    The lsusb command lists devices that are connected to your computer's USB ports and USB-enabled devices that are built into your computer.

      lsusb 

     lsusb in a terminal window

    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.

     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 get a more detailed listing by using the option -v (verbose) and a more verbose version by using . vv .

    . 8 The lsdev Command

    The command lsdev displays information about all installed devices.

    This command generates a lot of output, so we're passing it less.

      lsdev | less 

     lsdev | less in a terminal window

    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[19659005] 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 less

    ] Note that you need to use sudo with 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 

     sudo lshw | less in a terminal window

    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.

      lsscsi 

     lsscsi in a terminal window

    Here are the SCSI devices attached to this test computer.

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

    . 11 The dmidecode Command

    The 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 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 =" .onerror = zero; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

    The 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 .

      hwinfo --short 

     hwinfo --short in a terminal window

    If you really want to see the finest details, repeat this and leave the option - short gone.

     Output from hwinfo to 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.lazyL .loadIfVisibleAndMaybeBeacon (this);

    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.




    Source link