- slide 1 of 4
The chown command first appeared in AT&T UNIX version 7. The chown command is similar to the chmod command but instead of changing permissions, chown changes the owner (hence the name ch - change and own - owner) of a file or directory.
- slide 2 of 4
Basics of ownership
Every file and directory in Linux has an owner. If you issue the command ls -l in your ~/ folder (that is your users' home folder) you might see returned something similar to this:
-rwxr--r-- 1 root root 685 2008-10-02 12:38 suspend.sh*
drwxr-xr-x 5 jlwallen jlwallen 4096 2008-10-15 12:45 Test/
-rw-r--r-- 1 jlwallen jlwallen 0 2008-11-14 12:56 test1
drwxr-xr-x 9 jlwallen jlwallen 4096 2008-09-09 12:57 THEMES/
drwxr-xr-x 13 jlwallen jlwallen 4096 2008-09-11 14:35 thunderbird/
drwx------ 15 jlwallen jlwallen 4096 2008-11-19 16:37 tmp/
As you can see, most every file but one is owned by jlwallen. That means that the user, in this case me (jlwallen) owns these files and can modify their permissions. There is one file, suspend.sh, that is owned by root. That means the user jlwallen can not change the permissions of that file. In fact, according to the permissions/ownership, the user jlwallen can only read the suspend.sh file.
- slide 3 of 4
The chown command is a very simple command to use. Of course, in order to change the ownership of a file you have to have permission to make the change. But let's say you can change the ownership of a file (or you must change ownership and have to either su to the root user or use sudo), to do this the command would be:
chown USERNAME FILENAME
(Where USERNAME is the actual user you want to own the file, and FILENAME is the actual file name.)
There is an added bonus with the chown command. You can also change the group ownership of a file as well. Say I want the file test1 to belong to user jlwallen but the group accounting. To do this I would issue the command:
chown jlwallen:accounting test1
Now the test1 file belongs to jlwallen and the accounting group (so anyone in the accounting group can access the file).
Like chmod you can issue chown recursively to change ownership of a directory and all the files within the directory. To do this you add the -R argument. So if test1 were a directory and you wanted it to belong to user jlwallen and group accounting you would issue the command:
chown -R jlwallen:accounting test1
- slide 4 of 4
The chown command will come in handy for you at some point in your Linux administration lifetime. Whether it's installing a new web-based application that has to be run by the apache group, or giving a group permission to access a certain file, chown is one of those commands that will collect dust until the day comes when you cannot move forward without its help.