I'm working on a Ubuntu Windows app on my Windows-10 PC, the result of uname -a
is the following:
Linux DOMINIQUEDS 4.4.0-17134-Microsoft #48-Microsoft Fri Apr 27 18:06:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux
I'm doing some C++ development, and I'd like to know which source files (*.cpp
or *.h
) are including the file Sample.h
, so I launched following command:
find ./ -name "*.cpp" -or -name "*.h" -exec grep -i "include" {} /dev/null \; | grep "Sample.h"
This seems not to be working: only the *.h
files, containing include
and Sample.h
on the same line, are given.
However I know for sure that the -o
construction for finding different kinds of files is correct:
find ./ -name "*.cpp" -or -name "*.h"
=> here I get a list of *.cpp
and *.h
files.
This leaves me with two possibilities:
- Either the behaviour is correct: the
-exec
parameter is only used on the lastfind
result. In that case, can somebody tell me how I can perform the-exec
on allfind
results? - Either the behaviour is wrong. In that case, does somebody know if this is a general Ubuntu problem/Windows-10 Ubuntu app problem/... and if any solution can be expected and when?
Thanks in advance
True, but the precedence of
-or
is not that high. Fromman find
:So:
Is like:
And not like:
You need:
(I assume you used
/dev/null
to makegrep
print the filename? The-H
option does that.)With modern
grep
, you don't needfind
at all e.g.or - better (given that the order of the search terms is unambiguous)