Previous Table of Contents Next

Module 18
chown (SV)


The external chown command lets you change the owner of a file or directory. As a normal user you can only change the ownership of files you already own. The super-user can change the ownership of any file, regardless of who owns the file. You can specify a user name or a user ID for the new owner.

BSD (Berkeley)
Some BSD systems allow the user to execute the chown command. But on most systems the chown command is a super-user-only type command.


Following is the general format of the chown command.

     chown [ -hR ] owner file_list
     chown [ -hR ] owner directory_list


The following options may be used to change how chown functions.

-h Changes the owner of the symbolic links instead of the owner of the files pointed to by the symbolic links.
-R Forces chmod to recursively descend the directory trees listed, changing the group ID of files and directories. If a symbolic link is encountered, its group ID is changed but it is not traversed.


The following arguments must be passed to the chown command.

owner The name of a user or the decimal user ID number specifying the new owner.
file_list One or more files to change the ownership from your user ID to the specified user ID of owner.
directory_list One or more directories to change the ownership from your user ID to the specified user ID of owner.


You must specify a valid user name or user ID. Only the owner of a file or directory can change the ownership, except for root, who can change the ownership of any file or directory.

If the set-user-ID or set-group-ID mode is enabled, the chmod command will disable it unless you are the super-user.


If the operating system is configured with the {POSIX_CHOWN_ RESTRICTED} option, then the owner of a file cannot change the owner of the file. Only root can change the owner ID in this configuration.


Refer to the chgrp, chmod, and ls commands described in modules 16, 17, and 84.


The chown command checks the /etc/passwd file for the new owner or user ID given on the command line. If the user name or user ID is found and the file is changeable, then chmod performs the change.


You may want someone else to own a file. If you are leaving the department or the company, you may want to give your files to other users. Since only the owner or the super-user can change the ownership, you may want to decide who needs which files. Thus you simply perform a chown for each file to change the ownership.

Typically, the super-user uses the chmod command more than any other user. Changing ownerships of files that have been changed by accident or left behind by someone for another user is a common reason.


In this activity you use the chown command to change the ownership of a temporary file, then you remove the file. Begin at the shell prompt.

1.  First create a file called tempfile. Type touch tempfile and press Return. If you like, list the files owner using the ls -l command.
2.  Now change the owner of the file by typing chown nancy tempfile and pressing Return. Now the file is owned by the user named nancy. You could have typed chown 51 tempfile to achieve the same results. This assumes there is a user named nancy whose user ID is 51.

On some SV and all BSD systems this command will not work because you must be root to use chown. If your system returns an error like "not owner," skip to step 4.

3.  Type ls -l and press Return to list the new owner of the tempfile.
4.  Type rm tempfile and press Return to remove the tempfile. If you are asked for a confirmation, type y and press Return.
5.  Turn to Module 16 to continue the learning sequence.

Previous Table of Contents Next