2024-09-28 20:48:51 发布
网友
如何从Python中的文件路径找到nfs共享的主机?在
例如,如果df -h给出:
df -h
Filesystem Size Used Avail Use% Mounted on /dev/sdb3 500G 200G 300G 40% / hostname:/local 1T 20G 980G 2% /mnt/drive
当给定/mnt/drive/file.txt时,如何得到“hostname”?在
/mnt/drive/file.txt
hostname
挂载点可以从mount -l的输出解析:
mount -l
#!/usr/bin/env python import subprocess mounts = {} for line in subprocess.check_output(['mount', '-l']).split('\n'): parts = line.split(' ') if len(parts) > 2: mounts[parts[2]] = parts[0] print(mounts)
然后可以将路径与mounts字典中的键进行比较,并进一步解析这些值以获得挂载点。在
mounts
来源:https://askubuntu.com/a/189990/124703
挂载点可以从
mount -l
的输出解析:然后可以将路径与
mounts
字典中的键进行比较,并进一步解析这些值以获得挂载点。在来源:https://askubuntu.com/a/189990/124703
相关问题 更多 >
编程相关推荐