Wednesday, May 1, 2024
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 14492  / 1 Year ago, fri, march 31, 2023, 8:54:31

there's a way to get the device name (/dev/sdx) with the mounted folder? i mean, get the assosiated device in a mount point using the mounted folder as the reference, or make a python dictionary with the mount points : devices...



i know that mount -l can get me the mounted file system info, but i don't really know how to strip it to make the dictionary...



any help?



Regards...


More From » command-line

 Answers
5

This is totally unrelated to Ubuntu, but here you are:



#!/usr/bin/env python

import subprocess

mounts = {}

for line in subprocess.check_output(['mount', '-l']).split('
'):
parts = line.split(' ')
if len(parts) > 2:
mounts[parts[2]] = parts[0]

print mounts

[#35485] Saturday, April 1, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tionverflow

Total Points: 500
Total Questions: 115
Total Answers: 120

Location: Northern Ireland
Member since Mon, Nov 14, 2022
1 Year ago
;