문제

Is there a single, universal bash shell variable or common Linux command that will reliably indicate if a given directory or file is on a remote filesystem -- be it NFS, SSHFS, SMB, or any other remotely mounted filesystem?

CONTEXT...
This a root-only access, single-user, multi-host Linux development "lab" using SSH and SSHFS for semi-seamless loose-coupling the systems. Relevent directory structure on each host is...

    /0
    /0/HOST1
    /0/HOST2
    /0/HOST3
    /bin
    /boot
      :

Directories in /0 are SSHFS mounted to '/' on the named host. 'Host1', etc. are mountpoint directories named for each host.

I could of course, establish an environment variable something like...

    REMOTE_FS=/0

...and test for the dirname starting with '/0'. However that's not very portable or reliable.

Obvious question...
Having made the effort to make it seamless, why do I want to know when accessing something non-local?

Answer...
Going through a mounted filesystem puts all the processing load on the initiating host. I'd like to know when I have the option of using SSH instead of SSHFS to offload the background processing (ls, grep, awk, etc) to the remote (and usually more powerful) host, leaving just the GUI and control logic on the local machine.

도움이 되었습니까?

해결책

df -l <file>

This will return a non-zero exit code if the file or directory is not local.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top