Imagine a situation where the system unit of the computer is located in a hard-to-reach place. And it is impossible to remove the device from the USB port. Then you can try to disconnect and reconnect all USB devices programmatically.

To accomplish this task, we need to write a small program using bash that will do all the work for us.

  1. First, let's create a file and open it in a text editor.
  2. Paste in the newly created script, the code below.
    for i in /sys/bus/pci/drivers/[uoex]hci_hcd/*:*; do
    [ -e "$i" ] || continue
    echo "${i##*/}" > "${i%/*}/unbind"
    echo "${i##*/}" > "${i%/*}/bind"
    How to reconnect all USB devices in Linux
  3. To execute a script, you need to set the executable flag for it.
    sudo chmod ugo+x
  4. Run the script (as root).
    sudo ./
Note that keyboards, mice, and other input devices are also USB devices. Therefore, during the execution of the script, they will turn off for a while.