教你在Linux中使用lsusb命令顯示有關USB設備信息
在Linux中我們使用lsusb命令列出USB設備及其屬性,lsusb用于顯示系統(tǒng)中的USB總線及其連接的設備信息。下面介紹如何安裝并使用。
系統(tǒng)環(huán)境
系統(tǒng):Centos7
安裝usbutils
默認Centos7系統(tǒng)中沒有l(wèi)susb命令,我們需要安裝usbutils安裝包,才能使用lsusb:
- [root@localhost ~]# yum -y install usbutils
列出usb設備信息
lsusb用于顯示有關系統(tǒng)中的USB總線及其連接的設備的信息,下面運行l(wèi)susb:
- [root@localhost ~]# lsusb
- Bus 001 Device 010: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
- Bus 001 Device 055: ID 0951:1665 Kingston Technology Digital DataTraveler SE9 64GB
- Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
- Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
- Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
- Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
lsusb將顯示系統(tǒng)內(nèi)部連接的驅動程序和設備。
上面輸出內(nèi)容解釋如下:
Bus 001 Device 055: ID 0951:1665 Kingston Technology Digital DataTraveler SE9 64GB
Bus 001: 表示第一個usb控制器,可以使用lspci|grep USB查看主機有幾個usb控制器
Device 055: 表示系統(tǒng)分配給這個金士頓存儲設備的設備號
ID: 表示usb設備的ID
Kingston Technology Digital DataTraveler SE9 64GB: 表示其制造商名稱和設備名稱
我們還看到,系統(tǒng)中還附有USB 2.0 root hub 驅動程序和USB 1.1 root hub 驅動程序。
使用樹狀類型顯示usb信息
使用-t選項,以樹狀結構顯示usb信息:
- [root@localhost ~]# lsusb -t
- /: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
- /: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 480M
- |__ Port 1: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 480M
- /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
- |__ Port 1: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 12M
- |__ Port 2: Dev 3, If 0, Class=Hub, Driver=hub/7p, 12M
- /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
數(shù)字12M、480M、5000M表示USB的傳輸速度。
- 12M表示12Mbit / s,這是USB 1.0 / 1.1類型
- 480M表示480Mbit / s,這是USB 2.0類型
- 5000M表示5Gbit / s,這是USB3.0類型
Linux從/usr/share/hwdata/usb.ids'識別USB設備的詳細信息。lsusb列出的vendor和device name都是從這個文件里面識別出來的。
如何列出USB詳細信息
使用-v參數(shù)查看usb詳細信息:
- [root@localhost ~]# lsusb -v | less
- Bus 001 Device 056: ID 0951:1665 Kingston Technology Digital DataTraveler SE9 64GB
- Device Descriptor:
- bLength 18
- bDescriptorType 1
- bcdUSB 2.00
- bDeviceClass 0 (Defined at Interface level)
- bDeviceSubClass 0
- bDeviceProtocol 0
- bMaxPacketSize0 64
- idVendor 0x0951 Kingston Technology
- idProduct 0x1665 Digital DataTraveler SE9 64GB
- bcdDevice 1.00
- iManufacturer 1 Kingston
- iProduct 2 DataTraveler 2.0
- iSerial 3 08606E6B6612FD50771C2A8B
- bNumConfigurations 1
- Configuration Descriptor:
- bLength 9
- bDescriptorType 2
- wTotalLength 32
- bNumInterfaces 1
- bConfigurationValue 1
- iConfiguration 0
- bmAttributes 0x80
- (Bus Powered)
- MaxPower 100mA
- Interface Descriptor:
- bLength 9
- bLength 9
- bDescriptorType 4
- bInterfaceNumber 0
- bAlternateSetting 0
- bNumEndpoints 2
- bInterfaceClass 8 Mass Storage
- bInterfaceSubClass 6 SCSI
- bInterfaceProtocol 80 Bulk-Only
- iInterface 0
- Endpoint Descriptor:
- bLength 7
- bDescriptorType 5
- bEndpointAddress 0x81 EP 1 IN
- bmAttributes 2
- Transfer Type Bulk
- Synch Type None
- Usage Type Data
- wMaxPacketSize 0x0200 1x 512 bytes
- bInterval 255
- Endpoint Descriptor:
- bLength 7
- bDescriptorType 5
- bEndpointAddress 0x02 EP 2 OUT
- bmAttributes 2
- Transfer Type Bulk
- Synch Type None
- Usage Type Data
- wMaxPacketSize 0x0200 1x 512 bytes
- bInterval 255
- Device Qualifier (for other device speed):
- bLength 10
- bDescriptorType 6
- bcdUSB 2.00
- bDeviceClass 0 (Defined at Interface level)
- bDeviceSubClass 0
- bDeviceProtocol 0
- bMaxPacketSize0 64
- bNumConfigurations 1
- Device Status: 0x0000
- (Bus Powered)
查找連接了多少個USB設備
查找鏈接的設備數(shù)量,可以使用下面命令查找:
- [root@localhost ~]# find /dev/bus
- /dev/bus
- /dev/bus/usb
- /dev/bus/usb/002
- /dev/bus/usb/002/003
- /dev/bus/usb/002/002
- /dev/bus/usb/002/001
- /dev/bus/usb/001
- /dev/bus/usb/001/056
- /dev/bus/usb/001/010
- /dev/bus/usb/001/001
結合使用lsusb命令和-D參數(shù),可以輸出特定設備的詳細信息。下面實例查看金士頓存儲設備的詳細信息:
- [root@localhost ~]# lsusb -D /dev/bus/usb/001/056
查找大容量存儲設備
lsusb -v為我們提供了非常詳細的信息,我們可以配合使用grep命令查找指定的信息,下面過濾出idVendor和Mass Storage,來獲取大容量存儲設備:
- [root@localhost ~]# lsusb -v |grep -Ei '(idVendor|Mass\ Storage)'
- idVendor 0x0bda Realtek Semiconductor Corp.
- idVendor 0x0951 Kingston Technology
- bInterfaceClass 8 Mass Storage
- idVendor 0x1d6b Linux Foundation
- idVendor 0x0e0f VMware, Inc.
- idVendor 0x0e0f VMware, Inc.
- idVendor 0x1d6b Linux Foundation
可以看到只有idVendor是Kingston Technology的設備才是大容量存儲設備。