Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .