Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is it possible to on/off specific usb port using terminal in ubuntu?

lsusb displays the following result

Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 2232:1020  
Bus 002 Device 009: ID 0bc2:a013 Seagate RSS LLC 
Bus 002 Device 003: ID 0a5c:219c Broadcom Corp. 

Seagate is my external hard-disk. Can I power it off in terminal? I tried http://stackoverflow.com/questions/4702216/controlling-a-usb-power-supply-on-off-with-linux. But confused what should be replaced in place of usbX

share|improve this question

2 Answers 2

After running into the same problem, I found that the commands should be entered differently so that "sudo" would apply rights appropriately.

Use the "tee" command.

echo 0 | sudo tee /sys/bus/usb/devices/usb2/power/autosuspend_delay_ms

will apply root rights to the "tee" command which will write the 0 into the specified file, replacing anything that is currently there. To append, use the tee command with option -a.

for info see the man page of tee

share|improve this answer

Actually usbX is nothing but the USB ports numbers where X denotes the number like 1 or 2 and so on.. For example usb1 and usb2 for ports 1 and 2. In general a laptop may have 3 or 4 USB ports with USB 2.0 andUSB 3.0 ports.

In ubunty usb1, usb2...usbX are the links to /sys/devices/pci000:00/*. To understand it well run this command:

    ls -l /sys/bus/usb/devices/

So enable/disable USB ports usbX will be replaced to usb1 when you want to enable/disable USB Port Number 1 (or refer StackExchange):

Edit

Thanks to Stefan Denchev to tell the correct way to echo some text to a file using sudo. (Check his comment also.) You should not get permission denied message now.

sudo sh -c "echo '0' > /sys/bus/usb/devices/usb1/power/autosuspend_delay_ms"
sudo sh -c "echo 'auto' > /sys/bus/usb/devices/usb1/power/control"

After seeing your lsusb result it looks that your Seagate device is connected to Port No. 2 so you need to disable usb2, then commands would be:

sudo sh -c "echo '0' > /sys/bus/usb/devices/usb2/power/autosuspend_delay_ms"
sudo sh -c "echo 'auto' > /sys/bus/usb/devices/usb2/power/control"

Hope it works and you can understand now.

share|improve this answer
    
Thanks. If I try echo "0" > "/sys/bus/usb/devices/usb2/power/autosuspend_delay_ms" the output is bash: /sys/bus/usb/devices/usb2/power/autosuspend_delay_ms: Permission denied –  curious_coder Sep 6 '13 at 7:47
    
then try with sudo see what happens.. –  Saurav Kumar Sep 6 '13 at 7:51
    
Tried it. Still same error. –  curious_coder Sep 6 '13 at 7:52
    
Actually I didn't try to enable/disable any ports in Linux.. My motto was to make you clear about usbX problem. If you are much clear about the commands that you grabbed from StackOverflow then only you should give it a try. Any way now I am also interested to know which is actual command to enable/disable ports. I'll reply you soon, when it works for me. Tell then you unplug your device and try again. or try the first answer given at stackoverflow. –  Saurav Kumar Sep 6 '13 at 7:56
    
Sure............ –  curious_coder Sep 6 '13 at 8:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.