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

Linux systems have a /bin/mountpoint which can be used to check if a particular directory is a mount point for a volume. Does Mac OS X have an equivalent program, or is there some other way to run this check?

share|improve this question
up vote 3 down vote accepted

You can parse the output of mount for the directory you want to check (after on, enclosed by whitespace). This can't handle different paths due to symbolic links, though. A solution is available here, but it complicates this approach.

Alternatively, read the exit code of diskutil info, if it's non-zero, it's not a mount point.

#!/usr/bin/env bash
[[ $# -eq 1 ]] || { echo "Exactly one argument expected, got $#" ; exit 1 ; }
[[ -d "$1" ]] || { echo "First argument expected to be directory" ; exit 1 ; }
diskutil info "$1" >/dev/null
if [[ $RC -eq 0 ]] ; then
  echo "$1 is a mount point"
  echo "$1 is not a mount point"
exit $RC

If, for whatever reason you want the real mountpoint, do the following:

  1. Download the sources for sysvinit from here.
  2. Open src/mountpoint.c in a text editor of your choice and add #include <sys/types.h>
  3. Make sure you have Xcode and its command-line tools installed
  4. Run cc mountpoint.c -o mountpoint && sudo cp mountpoint /bin
  5. Optionally copy man/mountpoint.1 to /usr/share/man/man1.
share|improve this answer
That's a /no/, I guess…I'll accept this answer for now and just use diskutil info. I was hoping for a real mountpoint, but why complicate things, huh? Also, it should be noted that test's -ef mode follows symlinks (at least on this system), so you could extract the actual mount point from diskutil info and then check [ $1 -ef $mountpoint ]. – Blacklight Shining Aug 27 '12 at 21:32
@BlacklightShining There you go, real mountpoint. Quite trivial. Still don't see the point though. – Daniel Beck Aug 27 '12 at 22:22
mountpoint accepts a -q option to eliminate output, which eliminates the need to redirect anything. It's cleaner than redirection and IMO looks better in scripts and such. (I don't really feel like building it now, though, so I'll stick with running diskutil info.) – Blacklight Shining Aug 27 '12 at 23:08

You can use df command to get device node and mount point for any directory. To get mount point alone, use:

df "/path/to/any/dir/you/need" | sed -nE -e' s|^.+% +(/.*$)|\1|p'

This sed construct is used to get mount point which may include space in path. Notice usage of OS X's sed extended regexps option '-E', which is also unofficially supported by GNU sed (as GNU sed '-r' option). Portable command:

df "/path/to/any/dir/you/need" | sed -n -e' s|^.*% \{1,\}\(/.*$\)|\1|p'

You can use it in bash functions:

get_mount_point() {
    local result="$(df "$1" | sed -n -e' s|^.*% \{1,\}\(/.*$\)|\1|p' 2>/dev/null)" || return 2
    [[ -z "$result" ]] && return 1
    echo "$result"

is_mount_point() {
    [[ -z "$1" ]] && return 2
    [[ "$1" != "$(get_mount_point "$1")" ]] && return 1
    return 0
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.