23

I want to write a sh/bash script that can determine whether a particular directory is a mount point for an NFS filesystem.

eg something like

$ mkdir localdir
$ mkdir remotedir
$ mount host:/share ./remotedir
$ classify_dirs.sh
 -->  localdir is local
 -->  remotedir is an NFS mount point
Jani Uusitalo
  • 226
  • 1
  • 9
AndrewR
  • 10,759
  • 10
  • 45
  • 56

1 Answers1

46

This question is effectively a dup of how-can-i-tell-if-a-file-is-on-a-remote-filesystem-with-perl

The short answer is to use the stat command

eg

$ stat -f -L -c %T localdir
ext2/ext3
$ stat -f -L -c %T remotedir
nfs

Then a directory is an NFS mount point if its type is 'nfs' and its parent directory isn't.

Community
  • 1
  • 1
AndrewR
  • 10,759
  • 10
  • 45
  • 56
  • 1
    When I run this, I get the error `illegal option -- c`. Has stat changed substantially since this answer was written? – Dan Nov 23 '15 at 22:07
  • 1
    @DanI would guess its a Mac vs Linux delta – nhed Dec 31 '15 at 19:34