Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

Plan: I want to unmount an iscsi volume on my OS X Desktop in a script only if it's mounted. So far, I've identified the disk as disk4s2 with:

diskutil list | grep 'V-Movies' | rev | cut -c1-7 | rev... 

Continuing the line in order to unmount:

diskutil list | grep 'V-Movies' | rev | cut -c1-7 | rev | diskutil unmount [disk4s2]

but how do I refer to the disk in square brakets? I realize this may not be the most efficent solution. Any help would be appreciated.

share|improve this question

xargs is the command you need. It takes stdin and converts it to arguments to pass to a command.

Assuming that diskutil list | grep 'V-Movies' | rev | cut -c1-7 | rev gives you the disk name, do:

diskutil list | grep 'V-Movies' | rev | cut -c1-7 | rev | xargs diskutil unmount

share|improve this answer
Thanks, I'll try that – johne Sep 30 '12 at 21:37
The OP said, “only if it’s mounted.” If there’s a possibility that the disk isn’t mounted when the script is run, you should specify -r (or --no-run-if-empty) to xargs to tell it not to invoke diskutil unmount with no arguments if there is no data. – Scott Oct 1 '12 at 16:37
Good call @Scott :) – Alastair McCormack Oct 1 '12 at 18:52

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.