linux - 客户端的可编写脚本的磁盘使用情况分割

标签 linux bash shell centos7

我不是在寻找工具。我希望编写一个清晰的故障分析脚本,这样我就可以将其发送给不知道如何执行此操作的 VPS 用户。

我正在寻找一种通过 shell 脚本收集大量有关磁盘使用情况的数据的方法。在我的工作中,很多人打电话询问“为什么我的磁盘已满” 我运行 du -h --max-depth=1 | sort -rn 但这有点笨拙,我必须继续进一步挖掘......

我正在尝试通过这样的 shell 脚本来分割磁盘使用情况:

**home/ is consuming 400GB of disk space**</br>
home/user1 120GB
home/user2 200GB
**var/ is using 100GB of disk space**

到目前为止,我想出了以下内容:

#!/bin/bash
for i in $(ls -d */ |  grep -v proc);
 do
printf "**** $i has the following breakdown ********\n"

du -h --max-depth=1 $i
done

有什么方法可以为我的用户提供更清晰、更容易理解的磁盘使用情况分割?只是希望能够将用法包裹在漂亮的粉红色蝴蝶结中并说“祝你好运”

最佳答案

尝试一下ncdu (NCurses Disk Usage) ,例如:

$ ncdu -q -x

选项:

-q  Quiet mode. While scanning or importing the directory, ncdu will
    update the screen 10 times a second by default, this will be
    decreased to once every 2 seconds in quiet mode. Use this
    feature to save bandwidth over remote connections. 

 -x  Do not cross filesystem boundaries, i.e. only count files and
     directories on the same filesystem as the directory being
     scanned.

更多示例:https://dev.yorhel.nl/ncdu/man#EXAMPLES

关于linux - 客户端的可编写脚本的磁盘使用情况分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51492813/

相关文章:

linux - 使用串行控制台作为显示,但使用计算机键盘作为标准输入

mysql - 如何在 bash 中有效地将 long int 转换为 dotted quad IP

regex - 无法将否定先行断言应用于 bash 上的 nagios 插件输出

bash - 我如何编写一个 shell 脚本程序来遍历我所有的 esql 文件,然后执行该文件以创建 exe 文件

linux - 使用参数操作运行 shell 脚本

mysql - Arch linux 安装mysql access denied报错

linux - 在 32 位操作系统上,在内存中存储超过 3GB 的视频帧

c++ - 在Linux上构建Ogre时出错: narrowing conversion

linux - 打破 Bash 中的嵌套函数循环

linux - `sed` 模式匹配?