Tom Womack
Tom Womack

Reputation: 791

How to tell (in sh) whether a directory is mounted over NFS

df -t nfs $directory

returns two lines of output if the directory is NFS-mounted and one line if it isn't.

Some versions of df give exit status 1 if it wasn't NFS-mounted, but GNU coreutils 5.3.0 doesn't ...

if [ `df -t nfs . | wc -l` = 2 ]; 

feels inelegant and colleagues say that it doesn't check sufficiently for errors. Is there a better way to do this?

Upvotes: 5

Views: 2574

Answers (2)

Noufal Ibrahim
Noufal Ibrahim

Reputation: 72735

Duplicate question How do I determine if a directory is an NFS mount point in shellscript. Short answer, use the stat command.

Upvotes: 3

gymnodemi
gymnodemi

Reputation: 1

You could always check mtab it keeps a record of all mounted filesystems in a flatfile, if you use strace and look that is all df does anyway. I suppose you could also use /proc/mounts if your running this in Linux.

Upvotes: 0

Related Questions