How to chown Only Files That Need It

When using chown in initContainer or as startup Script it is advisable to combine it with find.

With chown only it will check and change every file to chown (in this example) which can take some time when applied to many files.

So you can combine chown with find. It will only apply chown on files that don't have desired uid/guid. Which will result in a much faster execution.

find /data ! -user 1000 -exec chown 1000:1000 /data -R {} \;