The following Gist describes the use of different commands to list all USB devices. Feel free to comment and contribute.
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.
df -Th | grep mediaWhere the output is:
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 |
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.
sudo parted -lWhere the output is:
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 |
The third option also requires the use of sudo to list the disk partition table with the command fdisk.
sudo fdisk -l | grep /dev/sWhere the output is:
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 |
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.
lsblk | grep sdWhere the output is:
sda 8:0 1 58,6G 0 disk /media/user/devicefindmnt 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.
findmnt | grep mediaWhere the output is:
└─/media/user/device /dev/sda ext2 rw,nosuid,nodev,relatimeThis 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.
lsusb -tvvWhere the output is:
/: Bus 02.Port 1: Dev 1, Class=root_hub, 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, Class=root_hub, 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, Class=Mass 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, Class=Video, 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, Class=Video, 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, Class=Video, 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, Class=Video, 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, Class=Wireless, 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, Class=Wireless, 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 |