[英]How to count files in specific subdirectories of a parent directory?
我使用find . -type f | wc -l
find . -type f | wc -l
find . -type f | wc -l
命令计算一个普通目录中的所有文件,但在更具体的情况下,如果一个目录包含许多文件,是否可以在命令中指定它? 例如,如果我只想计算image
子目录中的所有文件。 要知道我在mydirectory
中总共有多少图像(全部为 .jpeg)。
此命令有效find /Users/mydirectory -type f -exec file --mime-type {} \\; | awk '{if ($NF == "image/jpeg") print $0 }'
find /Users/mydirectory -type f -exec file --mime-type {} \\; | awk '{if ($NF == "image/jpeg") print $0 }'
find /Users/mydirectory -type f -exec file --mime-type {} \\; | awk '{if ($NF == "image/jpeg") print $0 }'
但只是显示它们。 如何计算它们?
最后命令find /Users/mydirectory -type f -exec file --no-pad --mime-type {} + | awk '$NF == "image/jpeg" {$NF=""; sub(": $", ""); print}' | wc -l
find /Users/mydirectory -type f -exec file --no-pad --mime-type {} + | awk '$NF == "image/jpeg" {$NF=""; sub(": $", ""); print}' | wc -l
find /Users/mydirectory -type f -exec file --no-pad --mime-type {} + | awk '$NF == "image/jpeg" {$NF=""; sub(": $", ""); print}' | wc -l
似乎可以解决问题。
mydirectory/
folder1/
image/
label/
folder2/
image/
label/
...
我的印象是您不知道find
命令的maxdepth
参数,该参数指示您的搜索命令的深度:通过使用find ... -maxdepth 1
您说您只想在目录本身内进行搜索。 我相信这会解决你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.