[英]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.我正在尝试使用 python 显示 linux 的分区,我想使用 API 来完成。 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
The folder /dev
contains various devices.文件夹
/dev
包含各种设备。 From these, devices named like sd[az]n
( /dev/sda1
, for instance) (on old machines with IDE drives hd[az]n)
, (where n-integer) are partitions.从这些中,命名为
sd[az]n
(例如/dev/sda1
)的设备(在带有 IDE 驱动器hd[az]n)
旧机器上hd[az]n)
,(其中 n 整数)是分区。 You can list using the file system access.您可以使用文件系统访问列表。
This has some limitations like unusual formatting of the whole drive as partition, but in general should work and also detect non-Linux partitions and with some luck USB sticks.这有一些限制,比如整个驱动器作为分区的异常格式化,但一般来说应该可以工作,并且还可以检测非 Linux 分区和一些幸运的 USB 记忆棒。
df command used for - report file system disk space usage df 命令用于 - 报告文件系统磁盘空间使用情况
I think you required fdisk for Partition table manipulator for Linux.我认为您需要 fdisk 用于 Linux 的分区表操纵器。
you can use either os.popen or subprocess.您可以使用 os.popen 或 subprocess。 just need root user login before running python script.
在运行python脚本之前只需要root用户登录。
我知道这很旧,但在 linux 上, /proc/partitions
是一个列出分区的特殊文件,但您可能需要/proc/mounts
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.