Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
find src/ -name "*.cc" -o -name "*.cpp" -print
find src/ -name "*.cc" -o -name "*.cpp"

The intended behavior is to find all C++ files in a directory and all its subdirectories. As I understood it, the -print command was the default. However, these two commands give me significantly different results. If I redirect them to a file (printed and notprinted, respectively):

$ wc -l printed notprinted
1813 printed
1979 notprinted

Diffing each sorted file doesn't help me much. There's no clear pattern for what's excluded from printed.

What's going on here?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

The answer is the precedence. If no action is given, then it prints, but if you specify an action then it does what you asked for. Your example with -print only prints .cpp files. You probably want:

find src/ \( -name "*.cc" -o -name "*.cpp" \) -print

You can have multiple conditions with different actions.

share|improve this answer
    
Ah, that's why. Figured it had to be something simple. I'll accept it as soon as it lets me. –  Robert Feb 7 '12 at 20:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.