Find, chown and exclude directories

chownfind

I would like to change the ownership of all files and directories but exclude some directories:

find -user test ! -path "./dir1/*" ! -path "./dir2/*" -exec chown -R root:root {} \;

The ownership of the excluded directories is still changed?

Regards

Best Answer

find . \( -path ./dir1 -o -path ./dir2 \) -prune -o -user test -exec chown root:root {} \;

Personally, for performance reasons, I prefer:

find . \( -path ./dir1 -o -path ./dir2 \) -prune -o -user test -print0 | xargs -0 chown root

Related Topic