Account
Categories

chown command


chown Command

Definition:

chown stands for Change Ownership.

When 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?

This way, you control who can manage or access the file/folder.


Example:

In your project, there are 5 people:

  • You → the owner
  • One person → a user
  • The rest → a group

Using chown, you decide the owner and group – permissions stay the same. (Permissions are set separately using chmod.)


Syntax:

chown [options] user:group filename

Options:

-R → Recursive

It changes the owner of a folder and everything inside it, including all files and subfolders.


Parameters:

  • user → Owner of the file/folder
  • group → Group of the file/folder (optional)
  • filename → Name of the file or folder

Note: Do not put a space between the user and group. It should be written like user:group. Correct format: shobha:developers


Step-by-Step Guide to Set Ownership Using chown

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, you choose the user and group to assign as the owner. Example:

sudo chown shobha:developers file.txt

Here, shobha becomes the owner, and the developers are the group that can access the file.

Step 4: To change ownership of a folder and everything inside it, use the -R option:

sudo chown -R shobha:developers myfolder

-R means all files and subfolders inside the folder will also get the new ownership.

Step 5: Check the ownership to confirm the change using:

ls -l

After typing this command, it will show a list of files and folders along with their owner, group, and other details.