Macos mac中目录及其子目录的特定文件类型的计数
我使用的是Macos mac中目录及其子目录的特定文件类型的计数,macos,unix,terminal,Macos,Unix,Terminal,我使用的是ls-l*.filetype | wc-l,但它只能在当前目录中找到文件。 如何计算子目录中具有特定扩展名的所有文件? 非常感谢。您可以使用find命令: find . -name "*.filetype" | wc -l 以下复合命令虽然有点冗长,但可以保证准确的计数,因为它正确: total=0; while read -rd ''; do ((total++)); done < <(find . -name "*.filetype" -print0) &&a
ls-l*.filetype | wc-l
,但它只能在当前目录中找到文件。如何计算子目录中具有特定扩展名的所有文件?
非常感谢。您可以使用
find
命令:
find . -name "*.filetype" | wc -l
以下复合命令虽然有点冗长,但可以保证准确的计数,因为它正确:
total=0; while read -rd ''; do ((total++)); done < <(find . -name "*.filetype" -print0) && echo "$total"
这将在“桌面”上生成以下目录结构:
注意:它总共包含四个.txt
文件。其中两个具有多行文件名,即b\n-file.txt
在较新版本的macOS上,名为b\n-file.txt
的文件将在“查找器”中显示为b?-file.txt
,即问号表示多行文件名中的换行符
find
的结果传输到wc-l
:
find ~/Desktop/test -name "*.txt" | wc -l
它不正确地报告/打印:
6
total=0; while read -rd ''; do ((total++)); done < <(find ~/Desktop/test -name "*.txt" -print0) && echo "$total"
total=0;当读取-rd“”时;do(total++);完成<
find ~/Desktop/test -name "*.txt" | wc -l
total=0; while read -rd ''; do ((total++)); done < <(find ~/Desktop/test -name "*.txt" -print0) && echo "$total"