Skip to main content
added 2 characters in body
Source Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k

It can be somewhat messy if the mount points contain blanks, but this should work except in cases where the mount points contain newlines:

#!/bin/sh mountpoint="$(df -P $1"$1" | awk '{ if (NR==1) i=index($0,"Mounted on"); else print substr($0,i); }')" mount|grep " on ${mountpoint} type " 

df -P outputs one line for the filesystem; without that option, df may output two lines if the mount point is long. The mount point name starts in the same column as does the "Mounted on" label in the header line.

After we get the mount point, we grep for it in the output of mount.

It can be somewhat messy if the mount points contain blanks, but this should work except in cases where the mount points contain newlines:

#!/bin/sh mountpoint="$(df -P $1 | awk '{ if (NR==1) i=index($0,"Mounted on"); else print substr($0,i); }')" mount|grep " on ${mountpoint} type " 

df -P outputs one line for the filesystem; without that option, df may output two lines if the mount point is long. The mount point name starts in the same column as does the "Mounted on" label in the header line.

After we get the mount point, we grep for it in the output of mount.

It can be somewhat messy if the mount points contain blanks, but this should work except in cases where the mount points contain newlines:

#!/bin/sh mountpoint="$(df -P "$1" | awk '{ if (NR==1) i=index($0,"Mounted on"); else print substr($0,i); }')" mount|grep " on ${mountpoint} type " 

df -P outputs one line for the filesystem; without that option, df may output two lines if the mount point is long. The mount point name starts in the same column as does the "Mounted on" label in the header line.

After we get the mount point, we grep for it in the output of mount.

Source Link
Mark Plotnick
  • 26.1k
  • 3
  • 68
  • 82

It can be somewhat messy if the mount points contain blanks, but this should work except in cases where the mount points contain newlines:

#!/bin/sh mountpoint="$(df -P $1 | awk '{ if (NR==1) i=index($0,"Mounted on"); else print substr($0,i); }')" mount|grep " on ${mountpoint} type " 

df -P outputs one line for the filesystem; without that option, df may output two lines if the mount point is long. The mount point name starts in the same column as does the "Mounted on" label in the header line.

After we get the mount point, we grep for it in the output of mount.