The chown Command

The chown command is used to change the owner and group of files, directories and links.

By default, the owner of a filesystem object is the user that created it. The group is a set of users that share the same access permissions (i.e., read, write and execute) for that object.

The basic syntax for using chown to change owners is

chown [options] new_owner object(s)

new_owner is the user name or the numeric user ID (UID) of the new owner, and object is the name of the target file, directory or link. The ownership of any number of objects can be changed simultaneously.

For example, the following would transfer the ownership of a file named file1 and a directory named dir1 to a new owner named alice:

chown alice file1 dir1

In order to perform the above command, most systems are configured by default to require access to the root (i.e., system administrator) account, which can be obtained on a personal computer by using the su (i.e., substitute user) command. An error message will be returned in the event that the user does not have the proper permissions or that the specified new owner or target(s) does not exist (or is spelled incorrectly).

The ownership and group of a filesystem object can be confirmed by using the ls command with its -l (i.e., long) option. The owner is shown in the third column and the group in the fourth. Thus, for example, the owner and group of file1 can be seen by using the following:

ls -l file1

The basic syntax for using chown to change groups is

chown [options] :new_group object(s)


chown [options] .new_group object(s)

The only difference between the two versions is that the name or numeric ID of the new group is preceded directly by a colon in the former and by a dot in the latter; there is no functional difference. In this case, chown performs the same function as the chgrp (i.e., change group) command.

The owner and group can be changed simultaneously by combining the syntaxes for changing owner and group. That is, the name or UID of the new owner is followed directly (i.e., with no intervening spaces) by a period or colon, which is followed directly by the name or numeric ID of the new group, which, in turn, is followed by a space and then by the names of the target files, directories and/or links.

Thus, for example, the following would change the owner of a file named file2 to the user with the user name bob and change its group to group2:

chown bob:group2 file2

If a user name or UID is followed directly by a colon or dot but no group name is provided, then the group is changed to that user's login group. Thus, for example, the following would change the ownership of file3 to cathy and would also change that file's group to the login group of the new owner (which by default is usually the same as the new owner):

chown cathy: file3

Among chown's few options is -R, which operates on filesystem objects recursively. That is, when used on a directory, it can change the ownership and/or group of all objects within the directory tree beginning with that directory rather than just the ownership of the directory itself.

The -v (verbose) option provides information about every object processed. The -c is similar, but reports only when a change is made. The --help option displays the documentation found in the man online manual, and the --version option outputs version information.

Created December 28, 2006.
Copyright © 2006 The Linux Information Project. All Rights Reserved.