4.6 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.
The chown
command supersedes chgrp
because all of the chgrp
command's functions are available in chown. However, many system
administrators still habitually use chgrp, and it is often found in
scripts and makefiles.
Syntaxchown [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. Since this program can handle all types of
changes to groups, it replaces the chgrp command. Only the superuser may
change file ownership, but group ownership may be set by
anyone belonging to the target group-owner.
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 of a file: # chown -v jdoe afile
owner of afile changed to jdoe
Example 2
As root, set the user and group of a
file: # chown -v jdoe.sales afile
owner of afile changed to jdoe.sales
Example 3
Recursively change the group of the entire
sls directory: # chown -Rv .sales sls
owner of sls changed to .sales
owner of sls/file1 changed to .sales
owner of sls/file2 changed to .sales
...
Syntaxchgrp [options] group-owner files
chgrp [options] --reference=rfile files
Description
Change the group parameter 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.
Remember that only root can change file
ownership. Also remember that chown can change not only the
user but also the group ownership.
|
|