What is the chown Command?
chown stands for change ownership. If you create a file or folder for your project, sometimes other people also need to work on it. To keep your files safe and organized, you set ownership. With this command, you set who becomes the owner of a file or folder, which group can access it, and who can manage or access the file or folder.
Syntax:
chown [options] user:group filename
Example:
Suppose you are working on a project with 5 people:
- You → the owner
- One person → a user
- The remaining people → a group
Using chown , you decide the owner and group. Permissions stay the same. (Permissions are set separately using chmod.)
Options:
-
-R → Recursive
It changes the owner of a folder and everything inside it, including all files and subfolders.
- user → Owner of the file or folder
- group → Group of the file or folder (optional)
- filename → Name of the file or folder
Note: Do not put a space between the user and group. It should be written as user:group. Correct format: shobha:developers.
Steps to Set Ownership Using chown Command:
Step 1: Open your terminal.
Step 2: Type sudo before the chown command. This lets you get the authority to assign a new owner to any file or folder.
Step 3: After entering this command, choose the user and group to assign as the owner.
Command:
sudo chown shobha:developers file.txt
Output:
Ownership of "file.txt" changed successfully.
Explanation:
Here, shobha becomes the owner, and the developers group is assigned to the file.
Step 4: To change the ownership of a folder and everything inside it, use the -R option.
Command:
sudo chown -R shobha:developers myfolder
Output:
Ownership of "myfolder" and all files and subfolders changed successfully.
Explanation:
The -R option changes the ownership of the folder and all files and subfolders inside it.
Step 5: Check the ownership to confirm the change.
Command:
ls -l
Output
-rw-r--r-- 1 shobha developers 0 Jul 17 10:30 file.txt drwxr-xr-x 2 shobha developers 4096 Jul 17 10:35 myfolder
Explanation:
This command displays the list of files and folders along with their owner, group, permissions, size, and other details.












