Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to write a shell script that ejects all currently-connected external drives (either USB or Firewire drives). I can use the disktuil eject <disk-path> to eject a specified drive. But I still can't figure how to find out what are the external drives. For instance, /Volumes shows internal drives, external drives, and mounted images. Is there a way to identify only external drives programmatically?

share|improve this question
up vote 4 down vote accepted

Have you considered using diskutil info /dev/disk[n|s{n}] | grep Ejectable which allows you to identify whether the device (or device slice) is ejectable.

This would need to be expanded upon in a script using awk to work through each disk device that is currently attached to determine whether it can be ejected and then eject it.

share|improve this answer
diskutil info is exactly what I need. I can use just grep to determine a "Yes" on the "Ejectable" line Here is my script as it might be useful to others: – ejel Jul 11 '11 at 23:44

In a terminal window (bash shell)

diskutil info /Volumes/name-of-volume

will return a list of properties of the volume, including

Protocol: FireWire ... Ejectable: Yes Whole: No Internal: No

so, I suppose you could start with that. I'm not clear on what the "Internal" property implies, it might be better to look at "Protocol" if your concern is with Firewire or USB external devices.

share|improve this answer

Your Answer


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.