bash 如何确定一个目录是否是 shellscript 中已挂载的 NFS 挂载点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/460047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 17:54:18  来源:igfitidea点击:

How do I determine if a directory is a mounted NFS mount point in shellscript

bashunixshellnfs

提问by AndrewR

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

我想编写一个 sh/bash 脚本来确定特定目录是否是 NFS 文件系统的挂载点。

eg something like

例如像

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

回答by AndrewR

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

这个问题实际上是一个重复的 how-can-i-tell-if-a-file-is-on-a-remote-filesystem-with-perl

The short answer is to use the statcommand

简短的回答是使用stat命令

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.

如果一个目录的类型是“nfs”而它的父目录不是,那么它就是一个 NFS 挂载点。