如何列出连接到 Linux 系统的 USB 设备
USB
![](/data/attachment/album/202208/30/094927nu106ijzz0iiiwj1.jpg)


你如何列出 Linux 中的 USB 设备？


这个问题可以有两种含义。


* 你的系统上有（检测到）多少个 USB 端口？
* 系统安装（插入）了多少个 USB 设备/磁盘？


大多数情况下，人们有兴趣了解哪些 USB 设备连接到系统。这可能有助于对 USB 设备进行故障排除。


最可靠的方法是使用这个命令：



```
lsusb

```

它显示了网络摄像头、蓝牙和以太网端口以及 USB 端口和挂载的 USB 驱动器。


![list usb with lsusb command linux](/data/attachment/album/202208/30/094930wejj6vcjyvyjilis.png)


但是理解 `lsusb` 的输出并不容易，当你只想查看和访问已挂载的 USB 驱动器时，你可能不需要那么复杂。


我将向你展示可用于列出连接到系统的 USB 设备的各种工具和命令。


除非另有说明，在我的例子中连接了一个 2GB 的 U 盘、1TB 的外置硬盘、通过 MTP 连接的 Android 智能手机，以及 USB 鼠标。


让我从桌面用户最简单的选项开始。


### 以图形方式检查连接的 USB 设备


你的发行版的文件管理器可以用来查看连接到你的计算机的 USB 存储设备。正如你在下面的 Nautilus（GNOME 文件管理器）的截图中看到的那样。


连接的设备显示在边栏中（此处仅显示 USB 存储设备）。


![Nautilus showing connected USB devices](/data/attachment/album/202208/30/094930o6ndrdittnttomzx.png)


你还可以使用 GNOME “<ruby> 磁盘 <rt>  Disks </rt></ruby>” 或 Gparted 等 GUI 应用来查看、格式化和分区连接到计算机的 USB 存储设备。默认情况下，大多数使用 GNOME 桌面环境的发行版都预装了 GNOME “磁盘”。


这个应用也可以用作一个非常好的 [分区管理器](https://itsfoss.com/partition-managers-linux/)。


![Use GNOME Disks to list mounted USB devices](/data/attachment/album/202208/30/094930p9i9xri9cn99dtid.png)


图形工具足够了。让我们讨论可用于列出 USB 设备的命令。


### 使用 mount 命令列出挂载的 USB 设备


`mount` 命令用于挂载 Linux 中的分区。你还可以使用相同的命令列出 USB 存储设备。


通常，USB 存储挂载在 `media` 目录中。因此，在媒体上过滤 `mount` 命令的输出将为你提供所需的结果。



```
mount | grep media

```

![](/data/attachment/album/202208/30/094931lde2vsruwpzjesuv.png)


### 使用 df 命令


[df 命令](https://linuxhandbook.com/df-command/) 是一个标准的 UNIX 命令，用于了解可用磁盘空间的大小。你还可以使用此命令列出已连接的 USB 存储设备。



```
df -Th | grep media

```

![Use df command to list mounted USB drives](/data/attachment/album/202208/30/094931d5025u2gnlka22k2.png)


### 使用 lsblk 命令


`lsblk` 命令用于列出终端中的块设备。因此，这里也通过过滤包含 `media` 关键字的输出，你可以获得所需的结果，如下面的截图所示。



```
lsblk | grep media

```

![Using lsblk to list connected USb devicesUsing blkid to list connected USb devices](/data/attachment/album/202208/30/094931y8q1d8v2ys8tl274.png)


如果你想知道，也可以使用 `blkid` 命令了解 UUID、标签、块大小等。


此命令提供更多输出，因为你的内部驱动器也被列出。因此，你必须参考上述命令来识别你希望了解的设备。



```
sudo blkid

```

![Using blkid to list connected USb devices](/data/attachment/album/202208/30/094931y8q1d8v2ys8tl274.png)


### 使用 fdisk


`fdisk` 是一款不错的老式命令行分区管理器，它还可以列出连接到你计算机的 USB 存储设备。这个命令的输出也很长。因此，通常连接的设备会列在底部，如下所示：



```
sudo fdisk -l

```

![Use fidsk to list usb devices](/data/attachment/album/202208/30/094932ig4vu49ds111gu36.png)


### 检查 /proc/mounts


通过检查 `/proc/mounts` 文件，你可以列出 USB 存储设备。如你所见，它向你显示了文件系统使用的挂载选项以及挂载点。



```
cat /proc/mounts | grep media

```

![](/data/attachment/album/202208/30/094932p2sogvggtgzswsga.png)


### 使用 lsusb 命令显示所有 USB 设备


我们重新审视有名的 `lsusb` 命令。


Linux 内核开发人员 [Greg Kroah-Hartman](https://en.wikipedia.org/wiki/Greg_Kroah-Hartman) 开发了这个方便的 [usbutils](https://github.com/gregkh/usbutils) 程序。这为我们提供了两个命令，即 `lsusb` 和 `usb-devices` 来列出 Linux 中的 USB 设备。


`lsusb` 命令列出系统中有关 USB 总线的所有信息。



```
lsusb

```

如你所见，此命令还显示了我已连接的鼠标和智能手机，这与其他命令（只能列出 USB 存储设备）不同。


![](/data/attachment/album/202208/30/094932c2230jsliyior2il.png)


第二个命令 `usb-devices` 提供了更多详细信息，但未能列出所有设备，如下所示。



```
usb-devices

```

![](/data/attachment/album/202208/30/094933lhlus4ucogha08hi.png)


Greg 还开发了一个名为 [usbview](https://github.com/gregkh/usbview) 的小型 GTK 应用。此应用向你显示连接到计算机的所有 USB 设备的列表。


该应用可在大多数 Linux 发行版的官方仓库中找到。你可以使用发行版的 [包管理器](https://itsfoss.com/package-manager/) 轻松安装 `usbview` 包。


安装后，你可以从应用菜单启动它。你可以选择任何列出的设备以获取详细信息，如下面的截图所示。


![](/data/attachment/album/202208/30/094933ez2m4pr6f22nz8mk.png)


### 总结


这里列出的大多数方法仅限于 USB 存储设备。只有两种方法可以列出其他外围设备； usbview 和 usbutils。 我想我们应该感谢 Linux 内核开发人员 Greg 开发了这些方便的工具。


我知道还有很多方法可以列出连接到系统的 USB 设备。 欢迎你提出建议。




---


via: <https://itsfoss.com/list-usb-devices-linux/>


作者：[Anuj Sharma](https://itsfoss.com/author/anuj/) 选题：[lkxed](https://github.com/lkxed) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

How do you list the USB devices in Linux?

The question can have two meanings.

- How many USB ports are (detected) on your system?
- How many USB devices/disks are
**mounted**(plugged in) to the system?

Mostly, people are interested in knowing what USB devices are connected to the system. This may help troubleshoot the USB devices.

The most reliable way is to use this command:

`lsusb`


It shows the webcam, Bluetooth, and Ethernet ports along with the USB ports and mounted USB drives.

![list usb with lsusb command linux](https://itsfoss.com/content/images/wordpress/2022/08/list-usb-with-lsusb-command-linux.png)

But understanding the output of lsusb is not easy and you may not need to complicate things when you just want to see and access the mounted USB drives.

I will show you various tools and commands you can use to list USB devices connected to your system.

I have connected a 2GB pen-drive, 1TB external HDD, Android smartphone via MTP and USB mouse in the examples unless stated otherwise.

Let me start with the simplest of the options for desktop users.

## Check connected USB devices graphically

Your distribution file manager can be used to view USB storage devices connected to your computer. As you can see in the screenshot of Nautilus (GNOME File Manager) below.

The connected devices are shown in the sidebar (Only USB Storage devices are shown here).

![Nautilus showing connected USB devices](https://itsfoss.com/content/images/wordpress/2022/08/nautilus-usb.png)

You can also use GUI applications like GNOME Disks or Gparted to view, format, and partition the USB Storage devices connected to your computer. GNOME Disks is preinstalled in most distributions using GNOME Desktop Environment by default.

This app also works as a very good [partition manager](https://itsfoss.com/partition-managers-linux/) too.

![Use GNOME Disks to list mounted USB devices](https://itsfoss.com/content/images/wordpress/2022/08/gnome-disks-usb.png)

* Enough of the Graphical tools*. Let us discuss the commands you can use for listing the USB devices.

## Using the mount command to list the mounted USB devices

The mount command is used for mounting partitions in Linux. You can also list USB storage devices using the same command.

Generally, USB storage is mounted in the media directory. Thus, filtering the output of mount command on media will give you the desired result.

`mount | grep media`


![](https://itsfoss.com/content/images/wordpress/2022/08/mount-cmd-usb.png)

## Using df command

[df command](https://linuxhandbook.com/df-command/?ref=itsfoss.com) is a standard UNIX command used to know the amount of available disk space. You can also use this command to list USB storage devices connected using the command below.

`df -Th | grep media`


![Use df command to list mounted USB drives](https://itsfoss.com/content/images/wordpress/2022/08/df-cmd-usb.png)

## Using lsblk command

The lsblk command is used to list block devices in the terminal. So, here also by filtering the output containing media keyword, you can get the desired result as shown in the screenshot below.

`lsblk | grep media`


![Using lsblk to list connected USb devicesUsing blkid to list connected USb devices](https://itsfoss.com/content/images/wordpress/2022/08/lsblk-cmd-usb.png)


![Using lsblk to list connected USb devicesUsing blkid to list connected USb devices](https://itsfoss.com/content/images/wordpress/2022/08/lsblk-cmd-usb.png)

If you are more curious, you can use the `blkid`

command to know the UUID, Label, Block size etc.

This command gives more output as your internal drives are also listed. So, you have to take references from the above command to identify the device you wish to know about.

`sudo blkid`


![Using blkid to list connected USb devices](https://itsfoss.com/content/images/wordpress/2022/08/blkid-cmd-usb.png)

## Using fdisk

fdisk, the good old command line partition manager, can also list the USB storage devices connected to your computer. The output of this command is also very long. So, usually, the connected devices get listed at the bottom as shown below.

`sudo fdisk -l`


![Use fidsk to list usb devices](https://itsfoss.com/content/images/wordpress/2022/08/fdisk-cmd-usb.png)

## Inspecting /proc/mounts

By inspecting the /proc/mounts file, you can list the USB Storage devices. As you can notice, it shows you the mount options being used by filesystem along with the mount point.

`cat /proc/mounts | grep media`


![](https://itsfoss.com/content/images/wordpress/2022/08/proc-dir-usb.png)

## Display all the USB devices with lsusb command

And we revisit the famed lsusb command.

Linux kernel developer [Greg Kroah-Hartman](https://en.wikipedia.org/wiki/Greg_Kroah-Hartman?ref=itsfoss.com) developed this handy [usbutils](https://github.com/gregkh/usbutils?ref=itsfoss.com) utility. This provides us with two commands i.e. `lsusb`

and `usb-devices`

to list USB devices in Linux.

The lsusb command lists all the information about the USB bus in the system.

`lsusb`


As you can see this command also shows the Mouse and Smartphone I have connected, unlike other commands (which are capable of listing only USB storage devices).

![](https://itsfoss.com/content/images/wordpress/2022/08/lsusb-cmd.png)

The second command `usb-devices`

gives more details as compared but fails to list all devices, as shown below.

`usb-devices`


![](https://itsfoss.com/content/images/wordpress/2022/08/usb-devices-cmd.png)

Greg has also developed a small GTK application called [Usbview](https://github.com/gregkh/usbview?ref=itsfoss.com). This application shows you the list of all the USB devices connected to your computer.

The application is available in the official repositories of most Linux distributions. You can install `usbview`

package using your distribution’s [package manager](https://itsfoss.com/package-manager/) easily.

Once installed, you can launch it from the application menu. You can select any of the listed devices to get details, as shown in the screenshot below.

![](https://itsfoss.com/content/images/wordpress/2022/08/usbview.png)

## Conclusion

Most of the methods listed are limited to USB storage devices. There are only two methods which can list other peripherals also; usbview and usbutils. I guess we have one more reason to be grateful to the Linux Kernel developer Greg for developing these handy tools.

I am aware that there are many more ways to list USB devices connected to your system. Your suggestions are welcome.