I'm using the below command to change the ownership (using chown) of sets directories and files present under a /opt/var
and trying to exclude .snapshot
directory and its contents.
find /opt/var/ ! -name '.snapshot' | xargs -I {} chown 2000:2000 {};
However, it only excludes .snapshot but its contents get permission applied.
Am I missing anything here? I am trying to achieve in one line.
CodePudding user response:
First of all, chmod
is for changing the permissions while chown
is for changing the owners. Anyways, to exclude a directory, use -path
option:
find /opt/var/ ! -path '/opt/var/.snapshot*' | xargs -I {} chown 2000:2000 {}
Or
find /opt/var/ ! -path '*.snapshot*' | xargs -I {} chown 2000:2000 {}