Is there a quick-and-dirty way to tell programmatically, in shell script or in Perl, whether a path is located on a remote filesystem (nfs or the like) or a local one? Or is the only way to do this to parse /etc/fstab and check the filesystem type?
stat -f -c %T <filename>
should do what you want. You might also want -l
您可以使用“df -T”获取目录的文件系统类型,或使用-t选项将报告限制为特定类型(如nfs),如果它返回“没有处理文件系统”,那么它不是一个你要找的那些。
df -T $dir | tail -1 | awk '{print $2;}'
If you use df
on a directory to get info only of the device it resides in, eg for the current directory:
df .
Then, you can just parse the output, eg
df . | tail -1 | awk '{print $1}'
to get the device name.
I have tested the following on solaris7,8,9 & 10 and it seems to be reliable
/bin/df -g <filename> | tail -2 | head -1 | awk '{print $1}'
Should give you have the fs type rather than trying to match for a "host:path" in your mount point.
On some systems, the device number is negative for NFS files. Thus,
print "remote" if (stat($filename))[0] < 0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.