【问题标题】:How to print only disk usage percentage of linux?如何仅打印linux的磁盘使用百分比?
【发布时间】:2021-05-11 06:50:39
【问题描述】:

如何只打印类似于内存百分比的linux磁盘使用百分比。

内存百分比我使用这个命令:

free -m | awk 'NR==2{printf "%.2f\t", $3*100/$2 }'

输出:

12.17

这样有什么命令可以知道磁盘使用百分比吗?

【问题讨论】:

标签: linux ubuntu diskspace


【解决方案1】:

使用df:

$ df
Filesystem      1K-blocks       Used Available Use% Mounted on
devtmpfs          1936588          0   1936588   0% /dev
tmpfs             1957840       7496   1950344   1% /dev/shm
tmpfs              783140       1864    781276   1% /run
/dev/sda6       518603776   12601324 504532516   3% /
tmpfs             1957844      27848   1929996   2% /tmp
/dev/sda6       518603776   12601324 504532516   3% /home
/dev/sda5          999320     289900    640608  32% /boot
tmpfs              391568       1696    389872   1% /run/user/1000
/dev/sdb1      1953512032 1952705324    806708 100% /run/media/mhawke/Seagate Expansion Drive

对于一个挂载点:

$ df /boot
Filesystem     1K-blocks   Used Available Use% Mounted on
/dev/sda5         999320 289900    640608  32% /boot

使用百分比:

$ df --output=pcent /boot
Use%
 32%

不包括标题:

$ df --output=pcent /boot | grep -v Use
 32%
$ usage=$(df --output=pcent /boot | grep -v Use)
$ echo $usage
32

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 2011-07-15
    相关资源
    最近更新 更多