Skip to main content
edited title
Link
Melab
  • 4.5k
  • 10
  • 42
  • 59

Shell code to check if a device or file with spaces in the path is mounted

Source Link
Melab
  • 4.5k
  • 10
  • 42
  • 59

Shell code to check if a device or file is mounted

The search results that I've turned up have either been about determining whether a filesystem is mounted at a particular path or whether a particular path is being used as a mount point. I am looking for a way to determine whther or not a given device or file (i.e., a filesystem image) is mounted at all. This solution should be able to handle spaces in the path to device/file.

These, which I have seen in my search results, are NOT solutions:

  • mountpoint -q "${PATH}" only tests if ${PATH} is a mount point.
  • Applying grep -q "${PATH}" to some output may not work because ${PATH} may have spaces in it and the output of commands like mount has spaces in it.

Additionally, it should return WHERE a file/device is mounted to.