6.7. Objective 6: Manage File Ownership Modification of ownership parameters may become necessary when moving files, setting up workgroups, or working in a user's directory as root. This is accomplished using the chown command, which can change user and group ownership, and the chgrp command for modifying group ownership.
Syntax chown [options] user-owner files chown [options] user-owner. files chown [options] user-owner.group-owner files chown [options] .group-owner files chown [options] --reference=rfile files
Description Used to change the owner and/or group of files to user-owner and/or group-owner. In the first form, user-owner is made the owner of files and the group is not affected. In the second form (note the trailing dot on user-owner), the user-owner is made the owner of files and the group of the files is changed to user-owner's default group. In the third form, both user-owner and group-owner are assigned to files. In the fourth form, only the group-owner is assigned to files, and the user is not affected. In the fifth form, the owner and group of rfile is used as a template and applied to files. Only the superuser may change file ownership, but group ownership may be set by anyone belonging to the target group-owner. Tip: Note that historically BSD systems have used the user.group syntax, but SysV-based systems have used user:group (: instead of .). Older versions of GNU chown only accepted the BSD syntax, but recent versions support both.
Frequently used options
-c Like verbose mode, but report only changes.
-R Use recursive mode, descending through directory hierarchies under files and making modifications throughout.
-v Use verbose behavior, reporting actions for all files.
Example 1 As root, set the user owner of a file: # chown -v jdoe afile owner of afile changed to jdoe
Example 2 As root, set the user and group owner of a file: # chown -v jdoe.sales afile owner of afile changed to jdoe.sales
Syntax chgrp [options] group-owner files chgrp [options] --reference=rfile files
Description Change the group owner of files to group-owner. In the first form, set the group-owner of files. In the second form, the group of rfile is used as a template and applied to files. Options and usage are the same as that of chown
Example 1 Recursively change the group owner of the entire sales directory: # chgrp -Rv sales sales changed group of 'sales' to sales changed group of 'sales/file1' to sales changed group of 'sales/file2' to sales ... |