Ownership
To change the owner of files or directories, use the chown
(change owner) command. The syntax is chown user:group path
where user
is the name of the owning user and group
is the name of the group, while path
is the full or relative part to the file or directory.
You can omit the colon and the group to just change the owning user and leave group ownership alone. Of course, the user attempting to change permissions on a file needs to have permission to do so, so in most situations this command will be run as the root
user.
In the following command snippet, you see a long listing of a file owned by root, which subsequently has its owner changed using the chown
command:
bash-3.2$ ls -l mysecret.txt
-rw-r--r-- 1 root staff 0 Apr 12 15:39 mysecret.txt
bash-3.2$ sudo chown dave mysecret.txt
bash-3.2$ ls -l mysecret.txt
-rw-r--r-- 1 dave staff 0 Apr 12 15:39 mysecret.txt