Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How to list ALL connected HDD devices in a script-friendly way? All - means both mounted and not mounted. Script-friendly - means something I can use for (u)mounting in my shell script with minimum grep'ing or sed'ing.

My task is to write some script which on startup will figure out where HDD is (if it's plugged in at all) and mount it. In my script I need some way to get list of available devices under /dev. What tool should I use in my script?

Here are options I considered:

  • fdisk -l gives much more information than I need - it is a bit hard to parse it's output in shell
  • parted -l does not list not mounted partitions and also outs a lot of extra information
  • cat /proc/partitions best output but does not list not mounted partitions

What tool fits my task the best way?

To clarify a bit where I'm coming from, here's my situation:

On some PC user will connect some HDD over USB or SATA. Then user restarts the PC. I know nothing about the HDD device, I can only assume that it has one partition with ext4 file system. The device could appear as /dev/sda or /dev/sdb. I have su access to the device and can add my script to /etc/rc.local or anywhere else but I have this access only before handing over the PC to the user.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Perhaps blkid which gives lines of the form:

/dev/sdXX: UUID="<UUID>" TYPE="<fstype>"

Also you can use those UUIDs in fstab: UUID="<UUID>" can replace the device path /dev/sdXX.

share|improve this answer

On distros that have udisks

 udisks --enumerate-device-files | grep -v ^/dev/disk
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.