I know we can list all mounted devices using the mount command. or even the df command.
But how can we know if the listed device is removable or not, such as USB, CMROM, External Hardisk, etc?
For this question, we can start with how to do it on SUSE or RedHat.
Thanks!
After thinking about this a bit more, the way to determine if a drive is removable is to check whether the contents of:
Is set to
0- non-removable or1- removable. You can get the list of mounted drives (presuming the form/dev/sdXwhereXisa,b,c, etc..) and then loop over the devices checking the contents of theremovablefile.For
bashusing Process-Substitution to feed awhileloop to loop over the device names removing the trailing partition digits and only taking unique devices you could do:Which will list all devices and whether they are removable. For example, running the script with a flash drive inserted (
/dev/sdc) and my normal hard drive (/dev/sdb), you would receive:There are probably many other ways to do it.