22

特定のディレクトリが NFS ファイルシステムのマウント ポイントであるかどうかを判断できる sh/bash スクリプトを作成したいと考えています。

たとえば、次のようなもの

$ mkdir localdir
$ mkdir remotedir
$ mount host:/share ./remotedir
$ classify_dirs.sh
 -->  localdir is local
 -->  remotedir is an NFS mount point
4

1 に答える 1

44

この質問は事実上 how-can-i-tell-if-a-file-is-on-a-remote-filesystem-with-perl の複製です

簡単な答えは、statコマンドを使用することです

例えば

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

その場合、ディレクトリのタイプが「nfs」で、親ディレクトリがそうでない場合、そのディレクトリは NFS マウント ポイントです。

于 2009-01-20T03:39:52.983 に答える