which-usb

Crates.iowhich-usb
lib.rswhich-usb
version0.1.0
created_at2025-08-13 13:50:16.004325+00
updated_at2025-08-13 13:50:16.004325+00
descriptionA command-line tool to list all currently connected USB devices
homepage
repositoryhttps://github.com/Uriel-090/which-usb
max_upload_size
id1793642
size28,145
(Uriel-090)

documentation

README

which-usb

A fast and lightweight command-line tool to list all currently connected USB devices on your system.

Features

  • 🚀 Fast USB enumeration - Quick listing of all connected USB devices
  • 📊 Multiple output formats - Table, JSON, and CSV output support
  • 🔍 Filtering capabilities - Filter by vendor ID or product ID
  • 📝 Verbose mode - Show detailed device information including manufacturer, product name, and serial numbers
  • 🎯 Cross-platform - Works on Linux, macOS, and Windows
  • Zero configuration - No setup required, just run and go

Installation

From Source

Make sure you have Rust installed, then:

git clone https://github.com/Uriel-090/which-usb.git
cd which-usb
cargo build --release

The binary will be available at target/release/which-usb.

Using Cargo

cargo install which-usb

Usage

Basic Usage

# List all USB devices in a simple table format
which-usb

# Show verbose information including manufacturer, product names, etc.
which-usb --verbose

# Short form
which-usb -v

Output Formats

# Table format (default)
which-usb --format table

# JSON format
which-usb --format json

# CSV format
which-usb --format csv

Filtering

# Filter by vendor ID (hexadecimal)
which-usb --vendor 046d

# Filter by product ID (hexadecimal)
which-usb --product c52b

# Combine filters
which-usb --vendor 046d --product c52b --verbose

Examples

Simple listing:

$ which-usb
Bus  Addr VID    PID    Speed          
----------------------------------------
001  001  1d6b   0002   High (480 Mbps)
001  002  8087   0024   High (480 Mbps)
001  003  046d   c52b   Full (12 Mbps)
002  001  1d6b   0003   Super (5 Gbps)

Total devices found: 4

Verbose listing:

$ which-usb --verbose
Bus  Addr VID    PID    Manufacturer         Product                        Serial          Speed          
--------------------------------------------------------------------------------------------------------------
001  001  1d6b   0002   Linux Foundation     2.0 root hub                  N/A             High (480 Mbps)
001  002  8087   0024   Intel Corp.          Integrated Rate Matching Hub  N/A             High (480 Mbps)
001  003  046d   c52b   Logitech, Inc.       Unifying Receiver             N/A             Full (12 Mbps) 
002  001  1d6b   0003   Linux Foundation     3.0 root hub                  N/A             Super (5 Gbps)

Total devices found: 4

JSON output:

$ which-usb --format json
[
  {
    "bus": 1,
    "address": 1,
    "vendor_id": 7531,
    "product_id": 2,
    "device_version": 1030,
    "manufacturer": "Linux Foundation",
    "product": "2.0 root hub",
    "serial_number": null,
    "class": 9,
    "subclass": 0,
    "protocol": 1,
    "max_packet_size": 64,
    "num_configurations": 1,
    "speed": "High (480 Mbps)"
  }
]

Command Line Options

which-usb [OPTIONS]

Options:
  -f, --format <FORMAT>    Output format [default: table] [possible values: table, json, csv]
  -v, --verbose           Show verbose device information
      --vendor <VENDOR>   Filter by vendor ID (hexadecimal, e.g., 1234)
      --product <PRODUCT> Filter by product ID (hexadecimal, e.g., 5678)
  -h, --help              Print help
  -V, --version           Print version

Understanding USB Device Information

  • Bus: The USB bus number the device is connected to
  • Addr: The device address on the bus
  • VID: Vendor ID - identifies the device manufacturer
  • PID: Product ID - identifies the specific product
  • Speed: USB connection speed (Low/Full/High/Super/Super+)
  • Manufacturer: Device manufacturer name (verbose mode only)
  • Product: Product name (verbose mode only)
  • Serial: Serial number (verbose mode only)

System Requirements

  • Linux: libusb-1.0 development package

    # Ubuntu/Debian
    sudo apt install libusb-1.0-0-dev
    
    # Fedora/RHEL
    sudo dnf install libusb1-devel
    
    # Arch Linux
    sudo pacman -S libusb
    
  • macOS: No additional dependencies (libusb is included with Xcode Command Line Tools)

  • Windows: No additional dependencies required

Permissions

On Linux and macOS, you might need appropriate permissions to access USB device information:

# Add your user to the appropriate group (Linux)
sudo usermod -a -G plugdev $USER

# Or run with sudo for full access
sudo which-usb --verbose

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under either of

at your option.

Troubleshooting

"Permission denied" errors

  • Try running with sudo or ensure your user has appropriate USB access permissions
  • On Linux, add your user to the plugdev group

"No devices found" when devices are connected

  • Check USB permissions
  • Verify libusb installation on Linux
  • Try running with elevated privileges

Build errors

  • Ensure you have the latest Rust toolchain
  • Install system dependencies (libusb-dev on Linux)
  • Check that you have a C compiler installed

Similar Tools

  • lsusb - Standard Linux utility for listing USB devices
  • system_profiler SPUSBDataType - macOS system profiler
  • Device Manager - Windows built-in device manager

which-usb aims to provide a consistent, cross-platform experience with modern output formatting options.

Commit count: 0

cargo fmt