Reputation: 10961
Given something like /dev/sdb1
, how can I find out where it was automounted to in linux in python (since using it directly like a directory does not work)?
(Continued from Why can't python glob detect my thumbdrive (and what can I do about it?))
Upvotes: 0
Views: 183
Reputation: 180502
You can use a subprocess with lsblk
and parse that or just parse /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"))
Upvotes: 1