gpt4 book ai didi

linux - 检查目录是否用 bash 挂载

转载 作者:IT老高 更新时间:2023-10-28 12:24:52 28 4
gpt4 key购买 nike

我正在使用

mount -o bind /some/directory/here /foo/bar

我想用 bash 脚本检查 /foo/bar,看看它是否已经挂载?如果不是,则调用上面的 mount 命令,否则执行其他操作。我该怎么做?

CentOS 是操作系统。

最佳答案

您没有费心提及操作系统。

Ubuntu Linux 11.10(可能是最新的 Linux 版本)具有 mountpoint 命令。

这是我的一台服务器上的示例:

$ mountpoint /oracle
/oracle is a mountpoint
$ mountpoint /bin
/bin is not a mountpoint

实际上,在您的情况下,您应该可以使用 -q 选项,如下所示:

mountpoint -q /foo/bar || mount -o bind /some/directory/here /foo/bar

希望对您有所帮助。

关于linux - 检查目录是否用 bash 挂载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9422461/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com