解析输出ls被认为是不好的做法.你可以使用find:
find . -iname 'ABC*' | wc -l
Run Code Online (Sandbox Code Playgroud)
man find:
-iname pattern
Like -name, but the match is case insensitive. For example, the
patterns `fo*' and `F??' match the file names `Foo', `FOO',
`foo', `fOo', etc. In these patterns, unlike filename expan?
sion by the shell, an initial '.' can be matched by `*'. That
is, find -name *bar will match the file `.foobar'. Please note
that you should quote patterns as a matter of course, otherwise
the shell will expand any wildcard characters in them.
Run Code Online (Sandbox Code Playgroud)
正如Johnsyweb在评论中指出的那样find,默认会将其递归到子目录中.为避免这种情况,您可以提供-maxdepth 1:
-maxdepth levels
Descend at most levels (a non-negative integer) levels of direc?
tories below the command line arguments. -maxdepth 0
means only apply the tests and actions to the command line
arguments.
Run Code Online (Sandbox Code Playgroud)