From LQWiki
Jump to: navigation, search

chown is the command to change ownership of a file or directory.

In Linux and other Unix-like operating systems, each user on the system has control about what other users can do to your files, and to whom does the files on the system belong to. The ownership of a file has a number of consequences, and in some cases, it may be useful to change the ownership of a file.

Changing ownership of a file means that you then are able to modify its permissions, and effectively lock another user out of reading or writing it. For this reason, other users are forbidden from changing the ownership of other users files, and thus, only the superuser is permitted to change ownership.

Using chown

Chown is used as follows:

chown owner file

For example, if you wanted to "give" the file picture.jpg to the user john, you could use

chown john picture.jpg

Instead of just the owner, the group can be changed as well, or both the user and group. Use a colon to seperate owner from group (with no space).

For example,

chown john:family picture.jpg

changes the owner of picture.jpg to john, and the group to family

Changing ownership of a tree

If you want to transfer ownership of a whole section of a tree, you can use:

chown -R /path/to/subtree

-R means "recursive."

For instance, if you want to change ownership of the immediate subtree to root, you can write:

chown -R root.root .

It is tempting to use "*" to refer to all files. However, this will not change ownership of dot files. It may also be tempting to use ".*", however, this will match against "..", and change ownership of all files in the parent directory as well! Note that the argument when using -R is a directory, not individually named files.

Provided by

Most (all?) Linux distributions incorporate this from the GNU Coreutils: man page

Related Commands

  • chgrp- Changes group ownership of a file
  • chmod - Changes the user/group permissions of a file/directory
  • ls - Lists files
  • touch - update timestamps