How to test if a given path is a mount point

后端 未结 10 839
-上瘾入骨i
-上瘾入骨i 2021-01-31 08:41

Suppose do you want test if /mnt/disk is a mount point in a shell script. How do you do this?

10条回答
  •  长发绾君心
    2021-01-31 08:58

    Here is a variant with "df -P" which is supposed to be portable:

    mat@owiowi:/tmp$ f(){ df -P  | awk '{ if($6 == "'$1'")print   }' ; }
    mat@owiowi:/tmp$ f /
    /dev/mapper/lvm0-vol1  20642428  17141492   2452360      88% /
    mat@owiowi:/tmp$ f /mnt
    mat@owiowi:/tmp$ f /mnt/media
    /dev/mapper/lvm0-media  41954040  34509868   7444172      83% /mnt/media
    

提交回复
热议问题