基于如何检查两个目录或文件是否属于同一个文件系统(https://unix.stackexchange.com/):
在 Linux 上的 shell 脚本中,可以使用stat完成:
Run Code Online (Sandbox Code Playgroud)stat -c "%d" /path # returns the decimal device number
这样你就可以:
file1=$(stat -c "%d" /path/file1)
file2=$(stat -c "%d" /path/file2)
Run Code Online (Sandbox Code Playgroud)
然后比较。
你也可以这样写:
if [ $(stat -c "%d" /path/file1) -eq $(stat -c "%d" /path/file1) ]
then
# mv sentence
fi
Run Code Online (Sandbox Code Playgroud)
其他选择。也取自Stackexchange 问题:
if [[ $(df -P /path/file1 | tail -1) = $(df -P /path/file2 | tail -1) ]]
then
# echo "same filesystem"
# mv sentence
fi
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
434 次 |
| 最近记录: |