Change file or directory ownership (user and/or group).
high risk
getfacl -R <path> > /tmp/acl.backupBack up ownership and ACLs.find <path> -user <old> -exec chown <new> {} +Change only files owned by a specific user.chown changes the owner and/or group of files. Format is user:group. Either can be omitted — chown user: changes owner and group to user's primary group; chown :group changes only the group.
| Flag | Meaning |
|---|---|
-R --recursive | Change ownership recursively |
-v --verbose | Print a message for each changed file |
--reference | Use a reference file's ownership |
chown nginx:nginx /var/www/htmlSet web root to nginx user and group · explain & risk-check →chown -R deploy:deploy /opt/appRecursively set ownership for app directory · explain & risk-check →chown root:root /usr/local/bin/myscriptSet ownership to root · explain & risk-check →chown --reference=/etc/passwd /etc/shadowMatch ownership from reference file · explain & risk-check →Use `chown user:` (trailing colon, no group) to change the user and automatically set group to that user's primary group — saves a lookup step.
Reference text is hand-written and may be incomplete — check man chown for your version. Test destructive commands on a non-production system first.