Command library / chown
chown
Change file owner and group
Changes WHO owns a file — as opposed to chmod, which changes what the owner is allowed to do. The form is owner:group, either half optional: 'deploy' changes just the owner, ':www-data' changes just the group, 'deploy:www-data' changes both at once.
Practice chownUsage
Options and flags
owner[:group]new owner and/or group
filefile or directory to change
-Rrecursive: apply to a directory and everything inside it
-vverbose: print every file that is changed
Examples
chown deploy backup.shGive the file to a new owner, leave the group untouched.
chown deploy:www-data /var/www/appSet both owner and group in one command — the classic web-deploy pattern.
chown -R deploy:www-data /var/www/appSame, but walk into every file and subfolder.
chown :www-data upload.phpChange only the group, leaving the owner exactly as it was.
Common mistakes
Owner and group are joined by a colon into ONE argument — a space between them makes chown think 'www-data' is a second file to change, not the group.