how to let wc command recursivly? [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
开发者_Python百科 Improve this questionLet it counting *.h *.cpp in Sub directory.
If you want it seperate per file:
find -type f \( -name "*.h" -o -name "*.cpp" \) -exec wc {} \;
if you want the accumulated sum:
find -type f \( -name "*.h" -o -name "*.cpp" \) -exec cat {} \; | wc -l
bash 4
shopt -s globstar
wc **/*.{cpp,h}
I think find
and xargs
is clearer and easier to work with instead of find -exec
but it's style choice.
find . -name "*.h" -or -name "*.cpp" | xargs wc
Use zsh instead of bash:
wc **/*.(cpp|h)
This will expand out to all the .cpp and .h files in the current directory and all subdirectories.
精彩评论