我不是在找工具。我希望写出一个很好的干净的分解,这样我可以把它发送给我的VPS用户,他们不知道如何做到这一点。
我一直在寻找一种通过shell脚本收集大量有关磁盘使用情况的数据的方法。在我的工作中,很多人打电话来问“为什么我的磁盘已满”,我运行du -h --max- -rn =1|-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有什么方法可以让我的用户更清晰、更容易地了解磁盘使用情况?我只想把用法包装在一个漂亮的粉色领结里,并说“祝你好运”
发布于 2018-07-24 17:01:40
试一试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.发布于 2018-07-24 18:59:31
这里有一个替代的解决方案。您可以使用tree以“类似树”的格式列出目录的内容。然后,您可以将其与磁盘使用标志相结合,以查看嵌套目录及其大小。
tree -L 2 --du -h'-L‘标志定义查询的深度或级别。
这将为您提供如下输出:

您甚至可以创建一个可以在浏览器中打开的xml文件,如下所示:
tree -L 2 --du -h -H s > disk_usage.html然后,您可以在浏览器中打开该文件,输出将如下所示:

希望这能有所帮助!
发布于 2018-07-24 15:42:50
你的代码片段是一个很好的开始,你不可能在一行代码中完成这个任务。一些文件夹,你需要一个深度>1(主页)和一些其他的深度=1 (var)
https://stackoverflow.com/questions/51492813
复制相似问题