0

Directory containing these files:

irrelevant  irrelevant.doc  dok1.txt  dok2.text  dok3.txt  dok4.text

I need to find all *txt and *text files and do some transformations on them.

find command and result:

$ find -name '*txt' -or -name '*text'
./dok2.text
./dok4.text
./dok3.txt
./dok1.txt

This is ideally the result I need, to pass these four files to -exec.

Unfortunately find with -print (or -exec echo {} +) produces:

$ find -name '*txt' -or -name '*text' -print
./dok2.text
./dok4.text

Apparently it's this case of find (from find man page):

NON-BUGS
   Operator precedence surprises
       The command find . -name afile -o -name bfile -print will never print afile
       because this is actually equivalent to find . -name afile -o \( -name bfile
       -a -print \).  Remember that the precedence of -a is higher than that of -o
       and when there is no operator specified between tests, -a is assumed.

How should the find command be given to have all four files available to -exec?

1 Answer 1

2

You need to group the or-ed expressions so that they, as a group, have the same precedence as and-ed expressions that follow:

find \( -name '*txt' -or -name '*text' \) -print

You must log in to answer this question.

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