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.

chown

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 ...

Get LPI Linux Certification in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.