简体   繁体   English

如何在 Linux 下识别 USB 存储“卷名”?

[英]How can I identify USB Storage "volume name" under Linux?

I'm trying to write a script that make a list of connected USBs list like this:我正在尝试编写一个脚本来制作一个连接的 USB 列表,如下所示:

  • MyFlash - ADATA MyFlash - 威刚
  • BootUSB - ADATA BootUSB - 威刚
  • MyBackup - SAN DISK MyBackup - SAN 磁盘

But I don't know how to identify the connected USB device is a storage one, and the volume name of it.但是我不知道如何识别连接的USB设备是存储设备,以及它的卷名。

C/C++, Python, or Node.js help are welcome, and only under Linux OS.欢迎使用 C/C++、Python 或 Node.js 帮助,并且仅适用于 Linux 操作系统。

I'm looking to mount and remount using code, but I think It will be easy to use Linux commands for this.我希望使用代码挂载和重新挂载,但我认为为此使用 Linux 命令会很容易。

Give this a shot:试一试:

udevadm info -a -n /dev/usbdevice

Further info:更多信息:

udevinfo -q all -n /dev/sda

Still further info:更进一步的信息:

lsusb -v
lshw

Use the command blkid(8) to identify UUID, filesystem type, volume label, etc of your visible/formatted partitions in your system.使用命令blkid(8)来识别系统中可见/格式化分区的 UUID、文件系统类型、卷标等。 It's used by the system scripts to collect information and mount filesystems, so you will have no problems in parsing its output.系统脚本使用它来收集信息和挂载文件系统,因此您在解析其输出时不会有任何问题。

如果已经挂载并且是您可以看到的以下任何类型的分区:

mount -l|grep -E 'fuseblk|vfat|ext4'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM