Average and maximum size of directories

耗尽温柔 提交于 2019-12-04 04:42:57

问题


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.


回答1:


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 } '



回答2:


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




回答3:


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}'


来源:https://stackoverflow.com/questions/2419690/average-and-maximum-size-of-directories

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!