3
1
I'm trying to count all files in a directory that match a pattern, recursively, using ls
:
ls -R | grep *.{cpp,h} | wc
However, I get:
zsh: no matches found: *.cpp
ls -R
does return results, though:
$ ls -R CMakeLists.txt cmake src
./cmake: Modules SUBS.cmake
./cmake/Modules: FindGecode.cmake
./src: A1_examples.h Sub1Main.cpp Sudoku.cpp Sudoku.h nQueens.cpp
Why doesn't grep
find the *.cpp
files that ls -R
returns?
Edit: I'm also pretty sure that ls -R | grep *.{cpp,h} | wc
is not the best way to do this, because of the way that ls
returns multiple results on single lines, but I'm not certain.
what kind of syntax is {cpp,h} ? – barlop – 2012-04-09T12:01:05.507
1As to the multiline: compare
ls
tols | cat
sometime.ls
is smart enough to do multicolumn only when reporting directly (or when told to do so explicitly); it assumes-C
for terminals and-1
for pipes. – geekosaur – 2012-04-09T12:07:53.307