Why are the files printed twice?
find . *.{h,cc} -maxdepth 1 -type f
./file7.h
./file8.h
./file9.cc
file7.h
file8.h
file9.cc
Is this correct? How do I spe开发者_开发技巧cify file patterns?
It's there twice because it's finding it first under .
, and then under the actual filename as given to find
as a place to search. Perhaps you meant to use -name
while escaping the wildcards.
find . -maxdepth 1 \( -name \*.h -o -name \*.cc \) -type f
If you're merely looking for files in the current directory, why not simply use:
$ shopt -s expglob
$ ls *.*(h|cc) */*.*(h|cc)
Otherwise, you have to do something liek this:
$ find . -maxdepth 1 -type f \( -name "*.h" -o -name "*.cc" \)
Using parentheses will do the or first, then combine it with the -type f and -maxdepth.
find *.{h,cpp} -maxdepth 1 -type f
This maybe help .
find . -name *.h -o -name *.cc -maxdepth 1 -type f
精彩评论