Joerg Wunsch <aus...@uriah.heep.sax.de> wrote, on 18 Oct 2017: > > As Martijn Dekker wrote: > > > Is there a way, using POSIX shell and utilities, to reliably test if two > > files are on the same file system? > > df -P appears to be required to have the filesystem name as the first > column. Filesystem names with a space however might be a problem, at > least if they contain a number after the space since that cannot be > distinguished from the number of blocks.
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:]].*//' -- Geoff Clare <g.cl...@opengroup.org> The Open Group, Apex Plaza, Forbury Road, Reading, RG1 1AX, England