Recursively find files with a specific extension
Using find
's -regex
argument:
find . -regex '.*/Robert\.\(h\|cpp\)$'
Or just using -name
:
find . -name 'Robert.*' -a \( -name '*.cpp' -o -name '*.h' \)
find -name "*Robert*" \( -name "*.pdf" -o -name "*.jpg" \)
The -o
repreents an OR
condition and you can add as many as you wish within the braces. So this says to find all files containing the word "Robert" anywhere in their names and whose names end in either "pdf" or "jpg".
As an alternative to using -regex
option on find
, since the question is labeled bash, you can use the brace expansion mechanism:
eval find . -false "-o -name Robert".{jpg,pdf}
My preference:
find . -name '*.jpg' -o -name '*.png' -print | grep Robert