简体   繁体   English

如何通过`lsusb`列出的总线号和设备号在`/dev`中找到设备文件?

[英]How can I find the device file in `/dev` via bus number and device number listed by `lsusb`?

When I attach removable USB hard disk to my computer, I can distinguish it from others via the name of manufacture and device name.当我将可移动 USB 硬盘连接到我的计算机时,我可以通过制造商名称和设备名称将其与其他硬盘区分开来。 However, I can't exactly know what is the device file in /dev (eg sda, sdb, sdc...) corresponding to this USB storage device.但是,我无法确切知道与此USB 存储设备对应的/dev(例如sda、sdb、sdc...)中的设备文件是什么。

Is there a way to find out the device file according to the output of lsusb ?有没有办法根据lsusb的输出找出设备文件?

I always do like this: If this USB device is the last one to remove/insert, you can get it from 'dmesg'.我总是这样做:如果这个 USB 设备是最后一个移除/插入的,你可以从 'dmesg' 获取它。 you can easy to see sdxxx in dmesg print out.您可以很容易地在 dmesg 打印输出中看到 sdxxx。 that's what your need.这就是你的需要。

You can know exactly the /dev/path/to/your/device using lsusb .您可以使用lsusb准确知道/dev/path/to/your/device

Sample output:示例输出:

Bus 002 Device 008: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

According to the previous example, you can locate the char device that corresponds to the Logitech USB receiver ( for wireless mouse and keyboard ) by examining the two numbers before the colon ( : ).根据前面的示例,您可以通过检查冒号 ( : ) 前的两个数字来定位与 Logitech USB 接收器(用于无线鼠标和键盘)对应的char设备。

It would be /dev/bus/002/008这将是/dev/bus/002/008
Notice the last two numbers ( last directory then the char device file itself ).注意最后两个数字(最后一个目录然后是char设备文件本身)。
They are the same as the first two numbers in the line that says Logitech, Inc. Unifying Receiver .它们与Logitech, Inc. Unifying Receiver行中的前两个数字相同。

So the path is always /dev/bus/ [first number] / [second number] .所以路径总是/dev/bus/ [first number] / [second number]

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

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