目录的平均和最大大小

发布于 2024-08-25 04:34:35 字数 232 浏览 3 评论 0原文

我有一个目录和一堆子目录,如下所示: - 目录1子目录1子目录2子目录3子目录4< /em>、sub-dir5......等等,数百个......)

我如何找出子目录的平均大小是多少? 如何找到子目录的最大大小是多少?

全部使用 Unix 命令...

谢谢。

I have a directory and a bunch of sub-directories like this:
- directory1 (sub-dir1, sub-dir2, sub-dir3, sub-dir4, sub-dir5...........and so on, hundreds of them...)

How do I find out what is average size of the sub-directories?
And how do I find what is the maximum size of the sub-directories?

All using Unix commands...

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尘曦 2024-09-01 04:34:35

如果 directory1 中只有目录而没有文件,那么以下两个“命令”应该为您提供最大目录的大小(以字节为单位)和名称以及它们的平均大小(以字节为单位) , 分别。

$ du -sb directory1/* | sort -n | tail -n 1
$ du -sb directory1/* | awk ' { sum+=$1; ++n } END { print sum/n } '

如果 directory1 中还有普通文件,则这些文件也将按照上面的示例进行计数。如果不应该计算普通文件,则以下内容可能更合适。

$ find directory1/ -mindepth 1 -maxdepth 1 -type d -exec du -sb {} \; | sort -n | tail -n 1
$ find directory1/ -mindepth 1 -maxdepth 1 -type d -exec du -sb {} \; | awk ' { sum+=$1; ++n } END { print sum/n } '

If you only have directories and not files in directory1, then the following two "commands" should give you the size (in bytes) and name of the largest directory and the average of their sizes (in bytes), respectively.

$ du -sb directory1/* | sort -n | tail -n 1
$ du -sb directory1/* | awk ' { sum+=$1; ++n } END { print sum/n } '

If there is also ordinary files within directory1, these will be counted as well with the examples above. If ordinary files should not be counted, the following might be more appropriate.

$ find directory1/ -mindepth 1 -maxdepth 1 -type d -exec du -sb {} \; | sort -n | tail -n 1
$ find directory1/ -mindepth 1 -maxdepth 1 -type d -exec du -sb {} \; | awk ' { sum+=$1; ++n } END { print sum/n } '
傲鸠 2024-09-01 04:34:35

我曾经遇到过 ext3 的问题,它只允许每个目录有 31998 个子目录。 Ext4 允许~64k。

I once had an issue with ext3, which only allows 31998 sub directories per directory. Ext4 allows ~64k.

猥︴琐丶欲为 2024-09-01 04:34:35

要获取最大大小 (KB),请使用 -b 代表字节

du -sk */|sort -n|tail -1

来获取平均大小 (KB)

du -sk */|awk '{s+=$1}END{print s/NR}'

to get the largest size (KB), use -b for bytes

du -sk */|sort -n|tail -1

to get average size (KB)

du -sk */|awk '{s+=$1}END{print s/NR}'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文