[英]How to find number of files in directory recursively along with its directory name linux
I have following structure in directory on linux: 我在linux的目录中具有以下结构:
-dirA
-dir1
-dirX
-dirY
-dir2
-dirX
-dirY
-dir2
-dirX
-dirY
-dir2
-dirX
-dirY
-dir2
-dirX
-dirY
-dir2
-dirX
-dirY
.
.
.
.
.
.
.
.
.
-dirn
-dirX
-dirY
I want to get details for count of files as follows or any format: 我想按以下或任何格式获取文件计数的详细信息:
dir1
dirX = count
dirY = count
dir2
dirX = count
dirY = count
dir3
dirX = count
dirY = count
......
......
dirn
dirX = count
dirY = count
note here folder name of dirX and dirY is same inside subdirectory dir1,dir2.....dirn 注意这里dirX和dirY的文件夹名称在子目录dir1,dir2 ..... dirn中是相同的
i used following command but it gives accumulated result: 我用下面的命令,但它给出了累积的结果:
find $DIR -exec stat -c '%F' {} \; | sort | uniq -c | sort -rn
and this 和这个
find . -type f | wc -l
A simple while
loop should be enough 一个简单的
while
循环就足够了
find "$DIR" -type d -print0 |
while IFS= read -r -d '' path; do
echo -e "$(ls -A -- "$path" | wc -l)\t$path"
done
If you want them sorted by file count, you can append a | sort -n
如果希望按文件计数对它们进行排序,则可以附加
| sort -n
| sort -n
at the end of the command (right after the done
keyword). 在命令末尾(在
done
关键字之后) | sort -n
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.