0

I am trying to delete a scsi disk using below command echo 1 > sudo /sys/block/sdb/device/delete. When I try to lsscsi after the command, I am still able to see the disk.

That would be great if some one can point where I am going wrong.

ilkkachu
  • 138,973
  • 2
    That command will create a file in the current directory called sudo with a line containing a single digit 1. – Kusalananda Jan 16 '18 at 11:03

1 Answers1

5

Where you're going wrong is in your understanding of how output redirection works.

Kusalananda's comment explains what happens -- the output of echo is directed into a file named sudo in the local directory. 1 and /sys/block/sdb/device/delete are arguments to echo, you'll find them in the output file.

Similarly, sudo echo 1 > /sys/block/sdb/device/delete won't work, because the sudo has not started yet when the shell sets up the output redirection.

If you really want to do it this way rather than su to root for a moment, you'll want:

echo 1 | sudo tee /sys/block/sdb/device/delete

or

sudo sh -c 'echo 1 > /sys/block/sdb/device/delete'

tee takes the input from stdin and writes it to the file specified as well as stdout, and can be run as root via sudo. In the latter command, the whole shell process runs under sudo.

ilkkachu
  • 138,973