目录的平均和最大大小 [英] Average and maximum size of directories
问题描述
我有一个目录和一堆这样的子目录:
- directory1 ( sub-dir1 , sub-dir2 ,sub-dir3 , sub-dir4 , sub-dir5 ...........等等,数百人...)
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?
所有使用Unix命令...
All using Unix commands...
谢谢。
推荐答案
如果您只有 directory1中的目录而不是文件
,那么以下两个命令应分别给出最大目录的大小(以字节为单位)和其大小的平均值(以字节为单位)。
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 } '
如果 directory1
,这些将与上面的示例一并计数。如果普通文件不应被计算在内,以下内容可能更合适。
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 } '
这篇关于目录的平均和最大大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!