Skip to content
Advertisement

Find all storage devices attached to a Linux machine [closed]

I have a need to find all of the writable storage devices attached to a given machine, whether or not they are mounted.

The dopey way to do this would be to try every entry in /dev that corresponds to a writable devices (hd* and sd*)……

Is there a better solution, or should I stick with this one?

Advertisement

Answer

/proc/partitions will list all the block devices and partitions that the system recognizes. You can then try using file -s <device> to determine what kind of filesystem is present on the partition, if any.

Advertisement