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?
The proper way to list block devices such as hard disks is using the command lsblk. Note: the -a flag forces lsblk to list also empty devices. In the first column you can see all the connected devices, in the image above you can see 3 devices: sda, sdc and sdd. Lets see some information on each.
All Linux device files are located in the /dev directory, which is an integral part of the root (/) filesystem because these device files must be available to the operating system during the boot process.
/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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With