- Juan-Embid / list_devices.md
- How to Use the LSUSB Command
- Install usbutils Package
- Using the lsusb Command
- Options Used with the lsusb Command
- Example 1: Display a Specific USB Device
- Example 2: Display Detailed Information about All USB Devices
- Example 3: Display Information about a Specific USB Device
- Example 4: Display All USB Devices in a Tree Structure
- Conclusion
- About the author
- Aqsa Yasin
Juan-Embid / list_devices.md
The following Gist describes the use of different commands to list all USB devices. Feel free to comment and contribute.
1. First option — DF Command
What you probably are looking for is the df command. This command (which reports the file system disk space usage) can be used along with grep to only print the lines that match the patterns we require, in our case, media. As no file name is given, it will look for mounted file systems so if your USB is encrypted and not already mounted it won’t be displayed.
device name mounted on /dev/sda ext2 58G 52M 55G 1% /media/user/device
Option | Description |
---|---|
-T | Print file system type |
-h | Human readable (print sizes in powers of 1024) |
-H | Print sizes in powers of 1000 |
2. Second option — PARTED Command
In this case we are going to list the USB devices using a partition manipulation program. This command is named parted and requires superuser (root) privileges.
Model: Vendors model (scsi) Disk /dev/sda: 62,9GB Sector size (logical/physical): 512B/512B Partition Table: loop Disk Flags: Number Start End Size File system Flags 1 0,00B 62,9GB 62,9GB ext2 Model: Your computer (nvme) Disk /dev/nvme0n1: 256GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 538MB 537MB fat32 EFI System Partition boot 2 538MB 2685MB 2147MB linux-swap(v1) swap 3 2685MB 4833MB 2147MB zfs 4 4833MB 256GB 251GB zfs
Option | Description |
---|---|
-l | Lists partition layout on all block devices |
-m | Use it along with -l option to display machine parseable output |
3. Third option — FDISK Command
The third option also requires the use of sudo to list the disk partition table with the command fdisk .
name Disk /dev/sda: 58,61 GiB, 62914560000 bytes, 122880000 sectors
Option | Description |
---|---|
-l | List the partition tables for the specified devices and then exit. If no devices are given, those mentioned in /proc/partitions are used |
4. Fourth option — LSBLK Command
Here the command lists block devices. The command prints all block devices (except RAM disks) in a tree-like format by default. sudo blkid | grep sd can also be used.
sda 8:0 1 58,6G 0 disk /media/user/device
5. Fifth option — FINDMNT Command
findmnt will list all mounted filesystems or search for a filesystem so if your USB is encrypted and not already mounted it won’t be shown.
└─/media/user/device /dev/sda ext2 rw,nosuid,nodev,relatime
6. Sixth option — LSUSB Command
This option won’t tell where the device is mounted or how it is called but list all USB devices and display information about its buses in the system and the devices connected to them. Type only one -v to show less information, two -vv for full information. Once you have identified the bus and dev variables of your USB device, then you could grep them to usb-devices for even more information.
/: Bus 02.Port 1: Dev 1, Driver=xhci_hcd/6p, 5000M ID 1d6b:0003 Linux Foundation 3.0 root hub /sys/bus/usb/devices/usb2 /dev/bus/usb/002/001 /: Bus 01.Port 1: Dev 1, Driver=xhci_hcd/12p, 480M ID 1d6b:0002 Linux Foundation 2.0 root hub /sys/bus/usb/devices/usb1 /dev/bus/usb/001/001 |__ Port 1: Dev 22, If 0, Storage, Driver=usb-storage, 480M ID 0930:6544 Toshiba Corp. TransMemory-Mini / Kingston DataTraveler 2.0 Stick /sys/bus/usb/devices/1-1 /dev/bus/usb/001/022 |__ Port 5: Dev 3, If 3, Driver=uvcvideo, 480M ID 05c8:0815 Cheng Uei Precision Industry Co., Ltd (Foxlink) /sys/bus/usb/devices/1-5 /dev/bus/usb/001/003 |__ Port 5: Dev 3, If 1, Driver=uvcvideo, 480M ID 05c8:0815 Cheng Uei Precision Industry Co., Ltd (Foxlink) /sys/bus/usb/devices/1-5 /dev/bus/usb/001/003 |__ Port 5: Dev 3, If 2, Driver=uvcvideo, 480M ID 05c8:0815 Cheng Uei Precision Industry Co., Ltd (Foxlink) /sys/bus/usb/devices/1-5 /dev/bus/usb/001/003 |__ Port 5: Dev 3, If 0, Driver=uvcvideo, 480M ID 05c8:0815 Cheng Uei Precision Industry Co., Ltd (Foxlink) /sys/bus/usb/devices/1-5 /dev/bus/usb/001/003 |__ Port 7: Dev 5, If 0, Driver=btusb, 12M ID 8087:0a2b Intel Corp. /sys/bus/usb/devices/1-7 /dev/bus/usb/001/005 |__ Port 7: Dev 5, If 1, Driver=btusb, 12M ID 8087:0a2b Intel Corp. /sys/bus/usb/devices/1-7 /dev/bus/usb/001/005
Option | Description |
---|---|
-t | Tells lsusb to dump the physical USB device hierarchy as a tree |
-v | Verbose. Tells lsusb to be verbose and display detailed information about the devices shown |
How to Use the LSUSB Command
The lsusb command, commonly known as the “List USB” command, is one of the most commonly used commands in Linux. As the name implies, this command is used to list all the USB devices that are attached to your Linux system. When combined with different parameters or options, this command can also be used to serve other purposes. This article shows you how to use the lsusb command in Linux.
Note: Linux Mint 20 is used throughout this article to demonstrate the usage of this command. However, you can work with any Linux distribution of your choice.
Install usbutils Package
Before getting started with the lsusb command, install the usbutils package onto your Linux Mint 20 system. To install the package, follow the steps shown below:
Launch the terminal by clicking on the terminal icon, highlighted in the following image:
After you click on this icon, the terminal window will immediately pop up, as shown below:
Before installing the usbutils package, it is highly recommended to update your Linux Mint 20 system to avoid hindrances during the installation. This can be done by executing the update command in the following manner:
This command can be seen in the image shown below:
Once your system has been updated, you will see the following output, as mentioned in the image on your terminal:
After successfully updating your system, you can now run the following command without any worries:
This command will install the usbutils package on your Linux Mint 20 system.
The successful installation of the said package will render the following output on your terminal:
Using the lsusb Command
The lsusb command provides information about the USB devices attached to your Linux system. This command may either be used individually or combined with various choices. For this section, we are only interested in running the lsusb command independently, i.e., without any additional parameters or options. Simply run the following command in your Linux Mint 20 terminal to do so:
Upon successful execution of this command, you will see all the information related to any USB buses and devices connected to your system, as in the following image:
Options Used with the lsusb Command
As mentioned previously, the lsusb command can also be used in conjunction with different options. These options include the following:
- -s: Displays information about any particular USB device, according to the device’s bus number and device number.
- -v: Shows more detailed information about the USB devices connected to your system.
- -D: Provides detailed information read from a specific USB device file.
- -t: Displays all the connected USB devices in the form of a tree or hierarchy.
In the examples given below, you will learn more about the usage of these options.
Example 1: Display a Specific USB Device
To display a specific USB device, you need to know two things about the device: its bus number and its device number. These two items can be determined simply by running the lsusb command alone, as discussed above. Once you know the bus and device numbers of the USB device, run the following command on your terminal:
Replace the BusNum and DeviceNum with the device’s bus number and device number, respectively. For the sake of demonstrating this method, we have used bus number 1 and port number 1, which you can verify in the image below:
After running this command, you will see the USB device, along with the specified bus number and device number on your terminal, as shown in the following image:
Example 2: Display Detailed Information about All USB Devices
To display every detail about all the USB devices that are connected to your system, run the following command in your terminal:
You can also see this command in the image below, for more clarity:
After this command is executed successfully, you will be able to see more details about all the USB devices connected to your system, as seen in the image below:
Example 3: Display Information about a Specific USB Device
As you may have noticed, in the method above, the output with the –v option was quite long. In some situations, you might want to have detailed information only about a single device, instead of having it for all the USB devices attached to your system. If this is the goal, then a detailed output about a single USB device can be achieved by executing the following command in your terminal:
Again, to run this command, you will need to know the bus number and device number of the specific USB device that you would like more information about from the device’s particular file. In this example, we have replaced the ‘BusNum’ with 001 and the ‘DeviceNum’ with 002, as shown in the image below:
After running this command, you will be able to see all the details about the specified USB device, read directly from the device’s file, as shown in the following image:
Example 4: Display All USB Devices in a Tree Structure
At times, you may also want to list down all the connected USB devices in the form of a hierarchy or a tree structure, for easier readability. This can be done by executing the following command in your terminal:
This command can also be seen in the image below:
Running this command will display all the USB devices that are connected to your system in the form of a tree structure, as shown in the following image:
Conclusion
This article gives you a detailed overview of the usage of the lsusb command in Linux Mint 20. Now, whenever you require more information about the USB devices attached to your system, you can conveniently make use of this command.
About the author
Aqsa Yasin
I am a self-motivated information technology professional with a passion for writing. I am a technical writer and love to write for all Linux flavors and Windows.