Resetting USB devices on Linux

Usbutils has a usbreset command that will reset a given USB device:

# usbreset 046d:0843
Resetting Logitech Webcam C930e ... ok

lsusb can be used to find the right device ID. This awk snippet may help with scripting (using the same Logitech webcam as an example again here):

$ lsusb | awk '/C930e/ { print $6 }'
046d:0843

Alternatively, to reset all of the attached USB ports, use this script1:

#!/bin/bash

for i in /sys/bus/pci/drivers/[uoex]{hci_hcd,hci-pci}/*:*; do
  [ -e "$i" ] || continue
  echo "${i##*/}" > "${i%/*}/unbind"
  echo "${i##*/}" > "${i%/*}/bind"
done