Suppose do you want test if /mnt/disk is a mount point in a shell script. How do you do this?
相关问题
- How to get the return code of a shell script in lu
- JQ: Select when attribute value exists in a bash a
- Invoking Mirth Connect CLI with Powershell script
- Why should we check WIFEXITED after wait in order
- Emacs shell: save commit message
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- In IntelliJ IDEA, how can I create a key binding t
- Check if directory exists on remote machine with s
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- Making new files automatically executable?
- Reverse four length of letters with sed in unix
- Launch interactive SSH bash session from PHP
Empty if is not a mountpoint ^^
Using GNU find
will give the device number of the directory. If it differs between the directory and its parent then you have a mount point.
Add /. onto the directory name if you want symlinks to different filesystems to count as mountpoints (you'll always want it for the parent).
Disadvantages: uses GNU find so less portable
Advantages: Reports mount points not recorded in /etc/mtab.
stat --printf '%m' shows the mount point of a given file or directory.
realpath converts relative paths to direct.
Comparing the results of the two will tell you if a directory is a mount point. stat is very portable. realpath is less so, but it is only needed if you want to check relative paths.
I'm not sure how portable mountpoint is.
Without realpath:
Here is a variant with "df -P" which is supposed to be portable:
I discover that on my Fedora 7 there is a mountpoint command.
From man mountpoint:
Apparently it come with the sysvinit package, I don't know if this command is available on other systems.
Unfortunately both mountpoint and stat will have the side-effect of MOUNTING the directory you are testing if you are using automount. Or at least it does for me on Debian using auto cifs to a WD MyBookLive networked disk. I ended up with a variant of the /proc/mounts made more complex because each POTENTIAL mount is already in /proc/mounts even if its not actually mounted!