【问题标题】:How to see where a device file was mounted to?如何查看设备文件的挂载位置?
【发布时间】:2016-03-03 20:14:59
【问题描述】:

鉴于/dev/sdb1 之类的内容,我如何才能在 python 中找到它在 linux 中的自动挂载位置(因为直接像目录一样使用它是行不通的)?

(续Why can't python glob detect my thumbdrive (and what can I do about it?)

【问题讨论】:

  • 您可以在/proc/mounts 中找到此信息。第一个空格分隔的字段是设备,第二个是安装点。

标签: python linux python-2.7 filesystems usb


【解决方案1】:

您可以使用带有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"))

【讨论】:

    猜你喜欢
    • 2014-07-20
    • 2018-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    相关资源
    最近更新 更多