---
updatedAt: 2025-08-14T18:06:40.000Z
agentTools:
  siteIndex: https://developer.n-able.com/llms.txt
  projectIndex: https://developer.n-able.com/n-central/llms.txt
---

# Linux - USB Device Inventory

```shell Shell Script
#!/bin/bash

# Parses /sys/bus/usb/devices/usb for devices/products that match the $MANIFEST. Returns device information, one device per line, comma separated values.

# To generate a manifest, download and run "Linux-Make-USB-Manifest.sh" on a machine with the desired devices connected
# Or run /usr/bin/usb-devices and compile the list of device Vendor IDs and Product IDs into the following format:
# MANIFEST="VendorID1,ProductID1 VendorID2,ProductID2 [...] VendorIDn,ProductIDn"

MANIFEST=$*

if [ -z $MANIFEST ]
then
	echo "A list of VendorID,ProductID objects is required."
	exit 1002
fi	


# List all the current USB devices and check vendorID and productID against $MANIFEST
for devicePath in /sys/bus/usb/devices/*
do

        if [ -f $devicePath/bDeviceClass ]
        then

# if the path includes a device, it will have a device class.
# check for "hub" class == "09" and skip

        deviceClass=`cat $devicePath/bDeviceClass`
#        echo $deviceClass

        # for each item found, check if it's in the manifest
                if [ $deviceClass != "09" ]
                then
                    	vendorID=`cat $devicePath/idVendor`
                        productID=`cat $devicePath/idProduct`

 #                       echo "${vendorID},${productID}"

                        if [[ "${MANIFEST[*]}" =~ "${vendorID},${productID}" ]]
                        then

                            	[ -f $devicePath/manufacturer ] && manufacturer=`cat $devicePath/manufacturer`|| manufacturer="N/A"
                                [ -f $devicePath/product ] && product=`cat $devicePath/product`|| product="N/A"
                                [ -f $devicePath/serial ] && serial=`cat $devicePath/serial` || serial="N/A"

                                USBDEVICE=$(printf '"%s","%s","%s",%s,%s' "$manufacturer" "$product" "$serial" "$vendorID" "$productID")

                                echo $USBDEVICE

                        fi

                fi

        fi

done


#exit 1001
```

```json Response Example
{"success":true}
```

# SCRIPT