Skip to content

Instantly share code, notes, and snippets.

@xlfe
Created April 19, 2014 00:43
Show Gist options
  • Save xlfe/11069850 to your computer and use it in GitHub Desktop.
Save xlfe/11069850 to your computer and use it in GitHub Desktop.
Disable non-USB drives in linux
#!/bin/bash
for d in $(find /sys/block -type l -name "sd*")
do
if [ -z "$(readlink -f $d | grep -i usb)" ]
then
echo "$d is a non-USB device, disabling access"
sudo bash -c "echo 1 > $d/device/delete"
else
echo "$d is a USB device"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment