chown
Change file owner and group.
Basic Usage
Change the owner of a file.
chown [user] [file]
Change the owner and group of a file simultaneously.
chown [user]:[group] [file]
Change only the group of a file (similar to chgrp).
chown :[group] [file]
Recursively change owner and group for a directory.
chown -R [user]:[group] [directory]
Advanced & Professional Scenarios
Reference Ownership
Copy ownership details from one file to another.
chown --reference=reference_file.txt [file]
Symlink Handling
Change the ownership of the symbolic link itself, not the target file.
chown -h [user]:[group] [file]
Conditional Changes
Change owner only if the file is currently owned by a specific user.
chown --from=olduser:oldgroup [user]:[group] [file]
Change owner only if the file is currently owned by a specific user (keep group).
chown --from=olduser [user] [file]
Web Server Setup
Set ownership for web root to the web server user (e.g., Nginx/Apache).
chown -R www-data:www-data /var/www/html
Fix ownership for a user's home directory (e.g., after copying files as root).
chown -R [user]:[user] /home/[user]
Verbose Output
Report only files that are actually changed.
chown -c [user]:[group] [file]