How can I programmatically enable and disable the power to a particular USB port on Linux? Is such a thing even possible? Mac answers appreciated as well!
I was tryi
You could use uhubctl - command line utility to control USB power per port for compatible USB hubs.
It works only on hubs that support per-port power switching, but note that many modern motherboards have USB hubs that support this feature. Also, last version of uhubctl supports USB 3.0 hubs, and good news is that quite a few new USB 3.0 hubs are supporting this feature.
To compile:
git clone https://github.com/mvp/uhubctl
cd uhubctl
make
To list status of all hubs and ports that can be controlled by uhubctl:
uhubctl
To turn off power on port 5 of single compatible hub:
uhubctl -a 0 -p 5
To turn on power for all ports of all compatible hubs:
uhubctl -a 1
To toggle power off then on:
uhubctl -a 2 -p 5
Read more here.
Disclosure - I am the author of uhubctl.