I'm trying to run the following:find . -user user_name -o -group user_group -exec chown root. {} \;But after running the command it doesn't alter the ownership of any files. If I run without the -exec it produces a list of all the files I expect to be modified correctly.If I use:find . -user user_name -exec chown root. {} \; find . -group user_group -exec chown root. {} \;The files are updated as expected. I see in the man page that:expr1 -o expr2          Or; expr2 is not evaluated if expr1 is true.expr1 -or expr2          Same as expr1 -o expr2, but not POSIX compliant.However, the files are owned by user_name:user_group. The first case should evaluate to true and run the exec command unless I'm misunderstanding something here. Can someone explain why this is working this way?Some system info if needed:find (GNU findutils) 4.4.2CentOS release 6.8 (Final)
'find' with '-o' and '-exec chown' not working as expected
find;chown
Logical operators in find syntax have lower precedence and in your example -o divides -user user_name and -group user_group -exec chown root. {} \;.Check the following:find . -user user_name -exec chown root. {} \; -o -group user_group -exec chown root. {} \;To avoid duplication use parentheses to evaluate the two test expressions together:find . \( -user user_name -o -group user_group \) -exec chown root. {} \;