2024-09-30 18:32:53 发布
网友
给定类似于/dev/sdb1的内容,我如何在python中找到它在linux中自动装载到的位置(因为像目录一样直接使用它是行不通的)
/dev/sdb1
(续自Why can't python glob detect my thumbdrive (and what can I do about it?))
您可以将子流程与lsblk一起使用并解析该子流程,或者只解析/etc/mtab:
lsblk
/etc/mtab
def find_mount(dev): with open("/etc/mtab") as f: for line in f: if line.startswith(dev): return line.split(None, 2)[1] print(find_mount("/dev/sdb1"))
您可以将子流程与
lsblk
一起使用并解析该子流程,或者只解析/etc/mtab
:相关问题 更多 >
编程相关推荐