[英]How can I find and count number of files matching a given string?
I want to find and count all the files on my system that begin with some string, say "foo", using only one line in bash. 我想找到并计算我的系统中所有以字符串开头的文件,比如“foo”,在bash中只使用一行 。
I'm new to bash so I'd like to avoid scripting if possible - how can I do this using only simple bash commands and maybe piping in just one line? 我是bash的新手,所以我想尽可能避免使用脚本 - 我怎样才能使用简单的bash命令来完成这项工作?
So far I've been using find / -name foo*
. 到目前为止,我一直在使用find / -name foo*
。 This returns the list of files, but I don't know what to add to actually count the files. 这将返回文件列表,但我不知道要添加什么来实际计算文件。
You can use 您可以使用
find / -type f -name 'foo*' | wc -l
-type f
to include only files (not links or directories). 使用-type f
仅包含文件(不包括链接或目录)。 wc -l
means "word count, lines only." wc -l
表示“单词计数,仅限行数”。 Since find
will list one file per line, this returns the number of files it found. 由于find
将每行列出一个文件,因此返回它找到的文件数。 你可以把它管道到wc
find / -name foo * | wc -l
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.