Skip to content
Advertisement

how to display linux partitions using python?

I am trying to display partitions of linux using python and i want to do it using APIs. I have just tried the following code to get the output.

import os

f = os.popen ("df -h")
for i in f.readlines():
print "myresult : ", i

Advertisement

Answer

df command used for – report file system disk space usage

I think you required fdisk for Partition table manipulator for Linux.

you can use either os.popen or subprocess. just need root user login before running python script.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement