nit*_*ian 17 filesystems shell mount
我有一个安装在特定目录上的tmpfs文件系统.我想编写一个shell脚本来检查tmpfs文件系统是否已经挂载在目录中.
Sor*_*gal 43
有一个专门用于此的工具:mountpoint(1)
if mountpoint -q "$directory" ; then
echo it is a mounted mountpoint
else
echo it is not a mounted mountpoint
fi
Run Code Online (Sandbox Code Playgroud)
你甚至不需要刮掉它就行了!
请注意,我在Debian的initscripts包中找到了这个工具.它在其他地方的可用性不是我可以评论的东西.
像这样的东西,虽然有点黑客,但应该可以解决问题:
FS_TO_CHECK="/dev" # For example... change this to suit your needs.
if grep -F " $FS_TO_CHECK " /proc/mounts > /dev/null; then
# Filesystem is mounted
else
# Filesystem is not mounted
fi
Run Code Online (Sandbox Code Playgroud)
您可以检查文件系统的类型。
$ stat -f -c'%T'/ xfs $ stat -f -c'%T'/ dev / shm tmpfs
您还可以通过将目录的设备与其父目录的设备进行比较来检查目录是否为挂载点。
$ stat -c'%D'/ 901 $ stat -c'%D'/ home fe01 $ stat -c'%D'/ home / $ USER fe01
| 归档时间: |
|
| 查看次数: |
25657 次 |
| 最近记录: |