Information Technology Reference
In-Depth Information
Changing File Ownership
Two commands are used to control the file ownership:
chown(1M) —Changes file user account ownership
chgrp(1M) —Changes file group account ownership
Changing File User Account
The chown command is used to change the file owner of a file or directory.
Only the superuser account (root) is allowed to change file ownership.
The user account name or associated UID is specified along with the name
of one or more files that should be owned by the specified user account. The
following listing shows the chown command being used to change the own-
ership of several files to the guest user account, which has a UID of 1001.
Each chown command is preceded and followed by the ls command, which
is used to list the ownership and permissions of files:
# ls -l
total 18
-rw-rw-rw- 1 root other 120 Jun 28 07:38 data
-rw-rw-rw- 1 root other 6528 Jun 28 07:38 junk
-rw-r--r-- 1 root other 636 Jun 28 07:39 list
# chown guest junk
# ls -l
total 18
-rw-rw-rw- 1 root other 120 Jun 28 07:38 data
-rw-rw-rw- 1 guest other 6528 Jun 28 07:38 junk
-rw-r--r-- 1 root other 636 Jun 28 07:39 list
# chown 1001 data list
# ls -l
total 18
-rw-rw-rw- 1 guest other 120 Jun 28 07:38 data
-rw-rw-rw- 1 guest other 6528 Jun 28 07:38 junk
-rw-r--r-- 1 guest other 636 Jun 28 07:39 list
#
The chown command supports a recursive command-line argument, -R .
When used to change the owner of a directory, the ownership of any files or
subdirectories under the directory also changes.
Even though a separate command exists to change file group account owner-
ship, the chown command can be used to change group ownership at the same
time by following the user account name or UID with the colon character and
a group account name or GID. The following example shows the chown com-
mand changing both user account ownership and group account ownership:
# ls -l
total 18
-rw-rw-rw- 1 guest other 120 Jun 28 07:38 data
-rw-rw-rw- 1 guest other 6528 Jun 28 07:38 junk
Search WWH ::




Custom Search