When using a Linux filesystem, every file and directory belongs to an owner and group.
Files and directories created by users, normally belong to them.
Operating system files and directories often belong to root.
Having file ownership makes unauthorized access more difficult, and increases the security of Linux operating systems.
There may be times when you want to change the owner and group of files or directories. For example, you may copy files from a USB drive using the root file manager, and they may belong to root.
To find out the owner and group, open the terminal and type:
Some file managers also display the owner and group.
The owner and group can be changed using the “chown” (change owner) command. Options include
chown [option] [owner][:[group]] file [more files]
The options within square brackets are optional.
For example, let's say you copied mylist.txt to /home/tc, and it belongs to root:root.
To change the owner and group to tc:staff, open the terminal and type
sudo su cd /home/tc chown tc:staff mylist.txt
The recursive option enables you to change the owner and group of a directory, and all files and directories within that directory, with one command. To do this use ”-R.”
For example, let's say you copied the directory myfiles to /home/tc, and it contains other files and directories, belonging to root:root.
To change the owner and group of all of these files and directories to tc:staff, open the terminal and type
sudo su cd /home/tc chown -R tc:staff myfiles
If you create a directory in another Linux partition to save files in, you may need to create it as root. It will then be owned by root. To save files in it, you then need to be root.
If you change the owner and group of the directory to tc:staff, you can save files in it as tc.