LPI Linux Certification in a Nutshell, 2nd Edition
by Steven Pritchard, Bruno Gomes Pessanha, Nicolai Langfeldt, James Stanger, Jeff Dean
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 fileschown [options] user-owner. fileschown [options] user-owner.group-owner fileschown [options] .group-owner fileschown [options] --reference=rfile files- Description
Used to change the owner and/or group of
filestouser-ownerand/orgroup-owner. In the first form,user-owneris made the owner offilesand the group is not affected. In the second form (note the trailing dot onuser-owner), theuser-owneris made the owner offilesand the group of the files is changed touser-owner's default group. In the third form, bothuser-ownerandgroup-ownerare assigned tofiles. In the fourth form, only thegroup-owneris assigned tofiles, and the user is not affected. In the fifth form, the owner and group ofrfileis used as a template and applied tofiles. Only the superuser may change file ownership, but group ownership may be set by anyone belonging to the targetgroup-owner.Tip
Note that historically BSD systems have used the
user.groupsyntax, but SysV-based systems have useduser:group(:instead of.). Older versions of GNU chown only accepted the BSD syntax, but recent versions support both.- Frequently used options ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access