The lsusb command is an essential tool for any Linux user. As a professional Linux coder and full-stack developer, I utilize lsusb on a regular basis to inspect and manage USB devices connected to my systems. In this comprehensive guide, I will demonstrate the proper usage of lsusb to list USB information, utilize helpful options, and better understand your Linux machine‘s USB configuration.

Installing LSUSB

Most Linux distributions come with lsusb pre-installed. However, if it is not already available, you can easily install it from your package manager.

On Debian/Ubuntu systems:

$ sudo apt update
$ sudo apt install usbutils

On RHEL/CentOS systems:

$ sudo yum update 
$ sudo yum install usbutils

This will fully install lsusb and all its required dependencies.

Using LSUSB to List All USB Devices

The most basic usage of lsusb simply lists information about all USB controllers and connected USB devices on your system:

$ lsusb

Here is some sample output:

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub 
Bus 001 Device 004: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 001 Device 003: ID 1a40:0101 Terminus Technology Inc. 4-Port 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

This gives you basic identification details on both the USB controllers that help manage device communication, as well as your currently connected USB devices like card readers, hubs, and more.

Using LSUSB Options

In addition to simple device listing, lsusb includes several options to tweak its output. These additional parameters give you alternative ways to view your USB information.

-v – Verbose Output

The -v option tells lsusb to output additional verbose descriptions about the devices:

$ lsusb -v

Instead of short one line identification strings, this adds paragraphs of detailed data like device descriptors, endpoints, configurations, and more.

-s [[bus]:[devnum]] – Output for Specific Device

You can also dig into a single USB device instead of viewing them all. The -s option lets you pick a device by bus and device number:

$ lsusb -s 001:003

This shows extended information just for the USB device located at bus 001 and device 003.

-t – Tree Output

For easier visualization of device relationships, use the -t formatting option:

$ lsusb -t

The tree format organizes devices with indentation representing bus connections:

/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/8p, 5000M
        |__ Port 1: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
        |__ Port 7: Dev 4, If 0, Class=Chip/SmartCard, Driver=, 12M

This provides a quick overview of device hierarchy on the USB controllers.

-D [[file]]:[devnum] – Device Info From Sysfs

For low-level USB device attributes directly from sysfs, use the -D option:

$ lsusb -D /dev/bus/usb/001/004 

This shows verbose technical data for the device read directly from sysfs instead of using libraries.

Advanced LSUSB Examples

With a grasp on the basic lsusb usage, as a Linux professional I regularly use more advanced techniques to truly unlock its capabilities:

Utilizing GREP

GREP allows me to filter down to specific USB devices when combing through verbose lsusb data:

  
$ lsusb -v | grep -i "1a40:0101"

This shows only lines related to my USB hub, making it easier to parse out information.

Monitoring Changes

To track when devices connect/disconnect, I pair lsusb with watch for live output:

$ watch -n 1 lsusb -t

Now lsusb runs every 1 second, letting me see USB changes in real-time.

UDEV Integration

For automated responses to USB events, I utilize lsusb data within UDEV rules:

ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="1a40", ATTR{idProduct}=="0101", NAME="my_usb_hub"  

So when my hub gets connected, custom scripts trigger thanks to lsusb identifying that USB device.

Conclusion

The lsusb command line tool is a multipurpose USB inspection utility packed with options for Linux users and developers. Mastering its variety of output formats and filters provides extensive access into the USB configuration of your systems. I hope this guide gives you the knowledge to leverage lsusb and better manage your USB devices.

Similar Posts