How to do it...

To understand the use of chown, let's follow these steps:

  1. To understand the use of the chown command, let's create a file named file1.txt and a user named user1:

The previous command for changing password information is optional. You can ignore it if you want to.

  1. Now, let's check the current owner of file1.txt.

We can see that the current owner for both the files is root and it belongs to the root group.

  1. Let's change the ownership of file1.txt to user1:

As seen here, the owner of file1.txt has now changed to user1.

  1. If we want to change the group of a file, we can do that also using chown:

  1. We can change both the owner and group of a file in single command as shown here:

We can see that the owner and group of file2.txt have changed.

  1. If we wish to recursively change ownership of a directory and its contents, we can do it as shown:

  1. Chown can also be used to copy the owner/group permissions from one file to another:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.26.246