First and foremost, this is going to depend solely on your architecture, and customs.
I for instance mount things like this under /mnt. I know people that create top level directories, and people who put this stuff in /home. It all depends on what you're comfortable with. There is no distinct standard on this anymore, the architecture of the system has changed, and you have varying views now, on things that used to be 'gospel'. Things like /usr/local or /opt/share, rpm or source...you get the drift.
Secondly, if you re-read through your link at pathname.com, you'll notice the paragraph under /media that states
Rationale
Historically there have been a number
of other different places used to
mount removeable media such as /cdrom,
/mnt or /mnt/cdrom. Placing the mount
points for all removeable media
directly in the root directory would
potentially result in a large number
of extra directories in /. Although
the use of subdirectories in /mnt as a
mount point has recently been common,
it conflicts with a much older
tradition of using /mnt directly as a
temporary mount point.
So personally, I advocate /mnt/windows or some iteration of that. It keeps the top level dir free, and is simple and intuitive. When I'm looking through or auditing a system, that's where I look for mounts right off the bat.
Under Linux, you can get mount point information directly from the kernel in /proc/mounts
. The mount
program records similar information in /etc/mtab
. The paths and options may be different, as /etc/mtab
represents what mount
passed to the kernel whereas /proc/mounts
shows the data as seen inside the kernel. /proc/mounts
is always up-to-date whereas /etc/mtab
might not be if /etc
was read-only at some point that wasn't expected by the boot scripts. The format is similar to /etc/fstab
.
In both files, the first whitespace-separated field contains the device path and the second field contains the mount point.
awk -v needle="$device_path" '$1==needle {print $2}' /proc/mounts
or if you don't have awk:
grep "^$device_path " /proc/mounts | cut -d ' ' -f 2
There are a number of edge cases where you might not get what you expect. If the device was mounted via a different path in /dev
that designates the same device, you won't notice it this way. In /proc/mounts
, bind mounts are indistinguishable from the original. There may be more than one match if a mount point shadows another (this is unusual).
In /proc/self
or /proc/$pid
, there is a per-process mounts
file that mimics the global file. The mount information may vary between processes, for example due to chroot
. There is an additional file called mountinfo
that has a different format and includes more information, in particular the device major and minor numbers. From the documentation:
36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue
(1)(2)(3) (4) (5) (6) (7) (8) (9) (10) (11)
(1) mount ID: unique identifier of the mount (may be reused after umount)
(2) parent ID: ID of parent (or of self for the top of the mount tree)
(3) major:minor: value of st_dev for files on filesystem
(4) root: root of the mount within the filesystem
(5) mount point: mount point relative to the process's root
(6) mount options: per mount options
(7) optional fields: zero or more fields of the form "tag[:value]"
(8) separator: marks the end of the optional fields
(9) filesystem type: name of filesystem of the form "type[.subtype]"
(10) mount source: filesystem specific information or "none"
(11) super options: per super block options
So if you're looking for a device by number, you can do it like this:
awk -v dev="$major:minor" '$3==dev {print $5}'
awk -v dev="$(stat -L -c %t:%T /dev/block/something)" '$3==dev {print $5}'
Best Answer
You could do something like
or even
Since
awk
splits on whitespace(s) by default, you don't need to specify the-F
and you also don't need to trim the whitespace withtr
. Finally, by specifying the line number of interest (NR==2
) you can also do away withtail
.