Reputation: 3
For some reason the command underneath only moves a certain amount of files and not all of them to the specified location:
find /directory1 -iname "*name1*" -or -iname "*name2*" -or -iname "*name3*" \
-or -iname "*name4*" -exec mv -v {} /directory2 \;
What is the reason of the problem?
Upvotes: 0
Views: 64
Reputation: 361987
You need to put parentheses around the -or
conditions so that the -exec
applies to all of them and not just the last one.
find /directory1 '(' -iname "*name1*" -or -iname "*name2*" -or -iname "*name3*" \
-or -iname "*name4*" ')' -exec mv -v {} /directory2 \;
There are implied -and
s between conditions and actions. When you write
find -cond1 -or -cond2 -or -cond3 -action
It's equivalent to
find -cond1 -or -cond2 -or -cond3 -and -action
Which due -and
having higher precedence than -or
, is equivalent to
find -cond1 -or -cond2 -or '(' -cond3 -and -action ')'
Upvotes: 3