前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python 查看服务器磁盘信息

Python 查看服务器磁盘信息

作者头像
py3study
发布2020-01-11 21:02:21
3.6K0
发布2020-01-11 21:02:21
举报
文章被收录于专栏:python3python3

查看磁盘信息,主要用到了两个方法

  • psutil.disk_partitions()
  • psutil.disk_usage()

使用方法: 1、安装 psutil

pip install psutil

2、进入 python shell,并 import psutil

输入 help(psutil.disk_partitions)

返回

代码语言:javascript
复制
Help on function disk_partitions in module psutil:

disk_partitions(all=False)
    Return mounted partitions as a list of
    (device, mountpoint, fstype, opts) namedtuple.
    'opts' field is a raw string separated by commas indicating mount
    options which may vary depending on the platform.

    If *all* parameter is False return physical devices only and ignore
    all others.

输入 help(psutil.disk_usage)

返回

代码语言:javascript
复制
Help on function disk_usage in module psutil:

disk_usage(path)
    Return disk usage statistics about the given *path* as a
    namedtuple including total, used and free space expressed in bytes
    plus the percentage usage.

3、应用

输入 psutil.disk_partitions()

代码语言:javascript
复制
>>> psutil.disk_partitions()
[sdiskpart(device='/dev/disk1', mountpoint='/', fstype='hfs', opts='rw,local,rootfs,dovolfs,journaled,multilabel'), sdiskpart(device='/dev/disk12s2', mountpoint='/Volumes/QQ', fstype='hfs', opts='ro,nosuid,quarantine,local,dovolfs,ignore-ownership,multilabel')]

输入 psutil.disk_usage(‘/’)

代码语言:javascript
复制
>>> psutil.disk_usage("/")
sdiskusage(total=120101666816, used=88392372224, free=31447150592, percent=73.8)

注:上述查到的大小信息单位为 bytes,因此,为了便于直观的观察使用量,应将其转换为M或G为单位的数据

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-08-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档