Tuesday, February 05, 2008

Linux : chown: Changes the owner of a file and/or the group the file is associated with

chown [options] owner file-list

chown [options] owner:group file-list

chown [options] owner: file-list

chown [options] :group file-list

chown [options] ––reference=rfile file-list


The chown utility changes the owner of a file and/or the group the file is associated with. Only root can change the owner of a file. Only root or the owner of a file who belongs to the new group can change the group a file is associated with.

Arguments

The owner is the username or numeric user ID of the new owner. The file-list is a list of the pathnames of the files whose ownership and/or group association you want to change. The group is the group name or numeric group ID of the new group that the file is associated with. Table V-9 shows the ways you can specify the new owner and/or group.

Table V-9. Specifying the new owner and/or group

Argument

Meaning

owner

The new owner of file-list; the group is not changed

owner:group

The new owner and new group association of file-list

owner:

The new owner of file-list; the group association is changed to that of the new owner's login group

:group

The new group associated with file-list; the owner is not changed


Options

Accepts the common options described on page 587.

––changes

–c

Displays a message for each file whose ownership/group is changed.

––dereference

Changes the ownership/group of the files symbolic links point to, not the symbolic links themselves. The default is ––no-dereference.

––quiet or ––silent

–f

Prevents chown from displaying error messages when it is unable to change the ownership/group of a file.


––no-dereference

–h

Changes the ownership/group of symbolic links, not the files that the links point to (default).

––recursive

–R

When you include directories in the file-list, this option descends the directory hierarchy, setting the specified ownership/group for all files encountered.


––reference=rfile

Changes the ownership and group association of the files in the file-list to that of rfile.

––verbose

–v

Displays for each file a message saying whether its ownership/group was retained or changed.


Notes

The chown utility clears setuid and setgid bits when it changes the owner of a file.

Examples

The following command changes the owner of the chapter1 file in the manuals directory. The new owner is Jenny:

# chown jenny manuals/chapter1


The following command makes Alex the owner of, and Alex's login group the group associated with, all files in the /home/alex/literature directory and in all its subdirectories:

# chown --recursive alex: /home/alex/literature


The next command changes the ownership of the files in literature to alex and the group associated with these files to pubs:

# chown alex:pubs /home/alex/literature/*


The final example changes the group association of the files in manuals to pubs without altering their ownership. The owner of the files, who is executing this command, must belong to the pubs group.

$ chown :pubs manuals/* 

No comments: