Martijn Dekker <mart...@inlv.org> wrote, on 21 Oct 2017: > > Op 19-10-17 om 15:06 schreef Martijn Dekker: > > Op 18-10-17 om 16:11 schreef Geoff Clare: > >> After the filesystem name there are four numeric fields with a trailing '%' > >> on the fourth. Treating this as the terminator for the filesystem name > >> ought to be good enough in practice. It would only not work in the > >> extremely unlikely event that a filesystem name has within it four numeric > >> fields with a trailing '%' on the fourth, or if two different filesystem > >> names are the same when trailing blanks are removed. > >> > >> I tried it with the following command and it seems to work: > >> > >> df -P file1 file2 | > >> sed '1d;s/\([[:blank:]]\{1,\}[[:digit:]]\{1,\}\)\{4\}%[[:blank:]].*//' > > > > That's very clever, and does seem to be fairly bullet-proof. Thanks! > > Hmm... on Linux, there can be several tmpfs mounts and they all have the > same file system name in the first column. Example: > > tmpfs 33039212 0 33039212 0% /dev/shm > tmpfs 33039212 3277180 29762032 10% /run > tmpfs 5120 0 5120 0% /run/lock > tmpfs 33039212 0 33039212 0% /sys/fs/cgroup > > Looks like we also need the mount point to uniquely identify a file > system. A little tweak to the sed incantation accomplishes that: > > df -P /dev/shm /run | > sed '1d; > s/\([[:blank:]]\{1,\}[[:digit:]]\{1,\}\)\{4\}%[[:blank:]]\{1,\}/,/' > > gives > > tmpfs,/dev/shm > tmpfs,/run > > But then, wouldn't it be sufficient simply to use the mount point only? > Can two file systems ever be on the same mount point?
Linux allows two mounts to the same mount point. (I tested it with "mount --bind ..."; not sure if it would work with a "real" mount.) However, the files in the first mount are inaccessible until the second is unmounted, so passing that mount point (or anything below it) to "df -P" only shows the second mount. So I think just comparing the mount points is indeed sufficient. -- Geoff Clare <g.cl...@opengroup.org> The Open Group, Apex Plaza, Forbury Road, Reading, RG1 1AX, England