Complete Guide to lsusb Command in Linux
Introduction
The lsusb command is a fundamental utility in Linux systems that provides detailed information about Universal Serial Bus (USB) devices connected to your system. This command is part of the usbutils package and serves as the primary tool for diagnosing, troubleshooting, and monitoring USB devices in Linux environments.
USB technology has become ubiquitous in modern computing, with devices ranging from simple storage drives to complex peripherals like printers, cameras, network adapters, and input devices. Understanding how to effectively use lsusb is crucial for system administrators, developers, and power users who need to manage USB connectivity and troubleshoot hardware issues.
Basic Syntax and Usage
The basic syntax of the lsusb command follows this pattern:
`bash
lsusb [options] [device_specifier]
`
The simplest form of the command requires no arguments:
`bash
lsusb
`
This basic invocation displays a list of all USB devices currently connected to the system, showing essential information including bus numbers, device addresses, vendor IDs, product IDs, and device descriptions.
Installation and Prerequisites
Most Linux distributions include lsusb by default as part of the usbutils package. However, if it's not installed on your system, you can install it using your distribution's package manager:
Ubuntu/Debian Systems
`bash
sudo apt update
sudo apt install usbutils
`Red Hat/CentOS/Fedora Systems
`bash
For newer versions using dnf
sudo dnf install usbutilsFor older versions using yum
sudo yum install usbutils`Arch Linux
`bash
sudo pacman -S usbutils
`Command Options and Flags
The lsusb command supports numerous options that modify its behavior and output format. Understanding these options is essential for effective USB device management.
| Option | Long Form | Description | |--------|-----------|-------------| | -v | --verbose | Display detailed information about each device | | -s | --bus | Specify bus and device numbers | | -d | --device | Show only devices with specified vendor:product ID | | -D | --device-path | Display information for device at specified path | | -t | --tree | Display devices in tree format showing topology | | -V | --version | Show version information | | -h | --help | Display help message |
Detailed Option Explanations
#### Verbose Output (-v, --verbose) The verbose option provides comprehensive information about USB devices, including configuration descriptors, interface descriptors, and endpoint information. This is particularly useful for developers and system administrators who need detailed technical specifications.
`bash
lsusb -v
`
#### Bus and Device Selection (-s, --bus)
This option allows you to specify particular bus and device combinations to examine specific USB devices. The format follows [[bus]:][devnum] pattern.
`bash
lsusb -s 001:002
lsusb -s 001:
lsusb -s :002
`
#### Device Filtering (-d, --device)
Filter output to show only devices matching specific vendor and product IDs. The format is [vendor]:[product] where IDs are in hexadecimal format.
`bash
lsusb -d 1234:5678
lsusb -d 1234:
lsusb -d :5678
`
#### Tree Display (-t, --tree) Shows the USB device topology in a hierarchical tree format, displaying how devices are connected through hubs and ports.
`bash
lsusb -t
`
Understanding lsusb Output
Standard Output Format
When executed without options, lsusb produces output in the following format:
`
Bus 001 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 003: ID 1234:5678 Example Corp. USB Device Name
`
Each line represents a connected USB device with the following components:
| Component | Description | Example | |-----------|-------------|---------| | Bus | USB bus number | Bus 001 | | Device | Device number on the bus | Device 003 | | ID | Vendor:Product identification | ID 1234:5678 | | Manufacturer | Device manufacturer name | Example Corp. | | Product | Product description | USB Device Name |
Verbose Output Interpretation
The verbose output provides extensive technical details about each device:
`bash
lsusb -v -d 1234:5678
`
This command produces detailed output including:
- Device descriptor information - Configuration descriptors - Interface descriptors - Endpoint descriptors - Device capabilities - Power consumption details - USB version compliance
Practical Examples and Use Cases
Example 1: Basic Device Listing
`bash
lsusb
`
Output:
`
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:8000 Intel Corp.
Bus 001 Device 003: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 004: ID 0781:5567 SanDisk Corp. Cruzer Blade
`
Example 2: Tree View Display
`bash
lsusb -t
`
Output:
`
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/12p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 9: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 12M
|__ Port 10: Dev 4, If 0, Class=Mass Storage, Driver=usb-storage, 480M
`
Example 3: Detailed Device Information
`bash
lsusb -v -s 001:004
`
This command provides comprehensive information about device 004 on bus 001, including technical specifications, power requirements, and supported features.
Example 4: Filtering by Vendor
`bash
lsusb -d 046d:
`
This shows all devices from Logitech (vendor ID 046d).
Advanced Usage Scenarios
Monitoring USB Device Changes
You can create scripts to monitor USB device connections and disconnections:
`bash
#!/bin/bash
USB monitoring script
while true; do clear echo "USB Devices - $(date)" echo "========================" lsusb sleep 2 done`Identifying Unknown Devices
When troubleshooting unknown USB devices:
`bash
List all devices with detailed information
lsusb -v | grep -E "^Bus|idVendor|idProduct|iManufacturer|iProduct"`Checking USB Version Support
To identify USB version capabilities:
`bash
lsusb -v | grep -E "bcdUSB|bMaxPacketSize0"
`
USB Device Identification and Vendor Codes
Understanding USB vendor and product codes is crucial for device identification. The USB Implementers Forum (USB-IF) assigns unique vendor IDs to manufacturers.
Common Vendor IDs
| Vendor ID | Manufacturer | |-----------|-------------| | 1d6b | Linux Foundation | | 8087 | Intel Corp. | | 046d | Logitech, Inc. | | 0781 | SanDisk Corp. | | 05ac | Apple, Inc. | | 045e | Microsoft Corp. | | 04f2 | Chicony Electronics Co., Ltd | | 0bda | Realtek Semiconductor Corp. |
Device Class Codes
USB devices are categorized by class codes that indicate their functionality:
| Class Code | Description | |------------|-------------| | 00h | Device class defined at interface level | | 01h | Audio | | 02h | Communications and CDC Control | | 03h | Human Interface Device (HID) | | 05h | Physical | | 06h | Image | | 07h | Printer | | 08h | Mass Storage | | 09h | Hub | | 0Ah | CDC Data | | 0Bh | Smart Card | | 0Dh | Content Security | | 0Eh | Video | | 0Fh | Personal Healthcare | | DCh | Diagnostic Device | | E0h | Wireless Controller | | EFh | Miscellaneous | | FEh | Application Specific | | FFh | Vendor Specific |
Troubleshooting with lsusb
Common Issues and Solutions
#### Device Not Recognized
When a USB device isn't recognized:
1. Check if the device appears in lsusb output 2. Verify power requirements 3. Test different USB ports 4. Check for driver issues
`bash
Check if device is detected
lsusb | grep -i "device_name"Check detailed device information
lsusb -v -d vendor:product`#### Permission Issues
USB device access may require appropriate permissions:
`bash
Check device permissions
ls -l /dev/bus/usb/001/002Add user to appropriate groups
sudo usermod -a -G plugdev username`#### Performance Issues
To diagnose USB performance problems:
`bash
Check USB version and speed
lsusb -v | grep -E "bcdUSB|MaxPower"Monitor USB tree topology
lsusb -t`Integration with Other Commands
The lsusb command works effectively with other Linux utilities for comprehensive system analysis.
Combining with grep
`bash
Find specific manufacturers
lsusb | grep "Intel"Find mass storage devices
lsusb -v | grep -A 10 "Mass Storage"`Using with dmesg
`bash
Check kernel messages about USB devices
dmesg | grep -i usbMonitor real-time USB events
dmesg -w | grep -i usb`Integration with udev
`bash
List udev rules for USB devices
ls /etc/udev/rules.d/usbMonitor udev events
udevadm monitor --subsystem-match=usb`Scripting and Automation
Creating USB Inventory Scripts
`bash
#!/bin/bash
USB Device Inventory Script
echo "USB Device Inventory Report" echo "Generated on: $(date)" echo "================================"
Count total devices
total_devices=$(lsusb | wc -l) echo "Total USB Devices: $total_devices" echo ""List devices by manufacturer
echo "Devices by Manufacturer:" lsusb | awk '{print $6, $7, $8, $9}' | sort | uniq -c echo ""Show USB topology
echo "USB Device Tree:" lsusb -t`Automated Device Detection
`bash
#!/bin/bash
Detect new USB devices
reference_file="/tmp/usb_baseline" current_file="/tmp/usb_current"
Create baseline if it doesn't exist
if [ ! -f "$reference_file" ]; then lsusb > "$reference_file" echo "Baseline created" exit 0 fiCompare current state with baseline
lsusb > "$current_file" diff "$reference_file" "$current_file" > /dev/nullif [ $? -ne 0 ]; then
echo "USB device changes detected:"
diff "$reference_file" "$current_file"
cp "$current_file" "$reference_file"
fi
`
Security Considerations
USB Security Monitoring
USB devices can pose security risks, and lsusb helps monitor for unauthorized devices:
`bash
Monitor for unknown devices
lsusb | grep -v -E "(Linux Foundation|Intel Corp|Known_Vendor)"Check for devices with unusual characteristics
lsusb -v | grep -E "iSerial|iManufacturer" | grep -v -E "known_patterns"`Device Whitelisting
Create scripts to validate against approved device lists:
`bash
#!/bin/bash
USB Device Whitelist Checker
whitelist_file="/etc/usb_whitelist" current_devices=$(lsusb | awk '{print $6}')
for device in $current_devices; do
if ! grep -q "$device" "$whitelist_file"; then
echo "Unauthorized device detected: $device"
# Log to syslog or take appropriate action
fi
done
`
Performance Analysis
USB Bandwidth Monitoring
Understanding USB bandwidth limitations and device requirements:
| USB Version | Maximum Speed | |-------------|---------------| | USB 1.0 | 1.5 Mbps (Low Speed) | | USB 1.1 | 12 Mbps (Full Speed) | | USB 2.0 | 480 Mbps (High Speed) | | USB 3.0 | 5 Gbps (SuperSpeed) | | USB 3.1 | 10 Gbps (SuperSpeed+) | | USB 3.2 | 20 Gbps | | USB4 | 40 Gbps |
Power Consumption Analysis
`bash
Check device power requirements
lsusb -v | grep -E "MaxPower|bMaxPower"Identify high-power devices
lsusb -v | grep -B 5 -A 5 "MaxPower.*[5-9][0-9][0-9]mA"`Conclusion
The lsusb command is an indispensable tool for managing USB devices in Linux systems. Its versatility ranges from simple device listing to complex troubleshooting and system analysis. Understanding its various options, output formats, and integration capabilities enables administrators and users to effectively manage USB connectivity, diagnose issues, and maintain system security.
Regular use of lsusb in system administration workflows helps maintain awareness of connected devices, identify potential issues before they become critical problems, and ensure optimal USB subsystem performance. Whether you're troubleshooting a non-functional device, conducting security audits, or developing automated monitoring solutions, lsusb provides the foundation for comprehensive USB device management in Linux environments.
The command's integration with other system utilities and its scriptable nature make it valuable for both interactive troubleshooting and automated system monitoring. As USB technology continues to evolve with new standards and device types, lsusb remains the primary tool for understanding and managing USB connectivity in Linux systems.