有它计算文件的bash命令? [英] Is there a bash command which counts files?
本文介绍了有它计算文件的bash命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有它计算与模式匹配的文件数bash命令?
Is there a bash command which counts the number of files that match a pattern?
例如,我想在一个目录中匹配这个模式所有文件的计数:日志*
For example, I want to get the count of all files in a directory which match this pattern: log*
推荐答案
这简单的一行,应在任何外壳,而不仅仅是工作的bash:
This simple one-liner should work in any shell, not just bash:
ls -l log* | wc -l
用ls -l可以给你每个文件一行,即使它们包含空格或制表符。
ls -l will give you one line per file, even if they contain spaces or tabs.
WC -l计数的行数
wc -l counts the number of lines.
如果您需要处理包含换行符的文件名,垫的回答能做到这一点。
If you need to handle file names containing newlines, Mat's answer can do that.
这篇关于有它计算文件的bash命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文