Change File Ownership with chown
If you want to change the owner of a file or directory, you can use the chown
command. The syntax is as follows:
chown DESIRED_OWNER PATH/TO/FILE
It is important to understand that as a regular user, you cannot change ownership of files or directories to have them belong to another user. However, the root account can. Consider the following example.
Let's suppose that you created a file called memo.txt
in the user chris’s home directory while you were root user. Here’s how you, as root, could change it to be owned by chris:
chown chris /home/chris/memo.txt
This will change ownership of memo.txt
to chris. However, this does not change the group owner, merely the user owner. If you wanted to change the group owner at the same time, you could have entered:
chown chris:chris /home/chris/memo.txt
Now, the file is also owned by the group joe.
The chown
command can also be employed recursively with the help of the -R
option. This is particularly useful when you need to modify the ownership of an entire directory structure to be owned by a specific user. For instance, if you've connected a USB drive, mounted it on the /media/myusb
directory, and wish to grant complete ownership of the drive's contents to the user chris, you can execute the following command:
chown -R chris:chris /media/myusb
Last updated
Was this helpful?