Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

If I do this find:

find ${TRIADS_DIR}/*.dc.results -path "*amblock/stats.*HEAD" -o -path "*amblock/stats.*BRIK"

then I get what I expect in STDOUT:

tp101.day1.dc.results/amblock/stats.tp101_day1+tlrc.HEAD
tp101.day1.dc.results/amblock/stats.tp101_day1+tlrc.BRIK
tp101.day2.dc.results/amblock/stats.tp101_day2+tlrc.HEAD
tp101.day2.dc.results/amblock/stats.tp101_day2+tlrc.BRIK
...

If I add an -exec clause to link the found files:

find ${TRIADS_DIR}/*.dc.results -path "*amblock/stats.*HEAD" -o -path "*amblock/stats.*BRIK" -exec ln -s {} ${TRIADS_GROUP} \;

then it only links the BRIKs:

stats.tp101_day1+tlrc.BRIK@
stats.tp101_day2+tlrc.BRIK@
...

Questions

  • What's happening?
  • Is there a more efficient way to tell find to return .HEAD and .BRIK using a single wildcard expression? I tried things like:

    find ${TRIADS_DIR}/*.dc.results -path "*amblock/stats.*{HEAD,BRIK}"
    

    but couldn't get it to work.

share|improve this question

marked as duplicate by Stéphane Chazelas, Karlson, Sukminder, vonbrand, Ramesh Jun 25 at 20:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

up vote 3 down vote accepted

Question 1: What's happening?

Your -o is splitting your arguments. The -exec only runs if the stuff on the same side of the -o is successful (the -path "*amblock/stats.*BRIK"). If you want -exec to run on both conditions, you need to wrap them in parenthesis:

find ${TRIADS_DIR}/*.dc.results \( -path "*amblock/stats.*HEAD" -o -path "*amblock/stats.*BRIK" \) -exec ln -s {} ${TRIADS_GROUP} \;

 

Question 2: Is there a more efficient way to tell find to return .HEAD and .BRIK using a single wildcard expression?

No, kinda. Some find implementations have a -regex non-standard predicate which you could use instead, but I wouldn't call that "more efficient".

share|improve this answer

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