简体   繁体   English

如何使用python显示linux分区?

[英]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.

相关问题 使用python3.x在Linux中查看分区 - view partitions in Linux using python3.x 如何使用 PYTHON 的“tkinter”模块在 CANVAS 上显示图像,特别是针对 linux? - How to display display an IMAGE on a CANVAS using PYTHON's "tkinter" module, Specifically for linux? Linux终端显示和Python - Linux Terminal Display and Python 如何通过 Pandas Python 中的分区对 dataframe 中的列进行等分? - How to decile a column in a dataframe by partitions in Pandas Python? 无法使用 Python 在 Windows Powershell 或 WSL Linux 终端中显示表情符号 - Cannot display emojis in Windows Powershell or WSL Linux Terminal using Python 如何使用 python cdk 启用动态分区创建 kinesis firehose 交付 stream? - How to create a kinesis firehose delivery stream with dynamic partitions enabled using python cdk? 如何使用mapPartitions在RDD的分区上运行python用户定义的函数? - How to run a python user-defined function on the partitions of RDDs using mapPartitions? 如何在 Linux 上找到运行 Python3 的显示器的分辨率? - How could I find the resolution of a display running Python3 on Linux? 使用python如何显示dns - Using python how to display dns 在Linux Angstrom上使用Python显示图像 - Display an image with Python on Linux Angstrom
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM