chown Linux Centos8/Redhat8/OracleLinux command

  • Last update: Apr 3, 2024
  • Views: 38
  • Author: Admin
chown Linux Centos8/Redhat8/OracleLinux command

Hello colleagues.

In today's article, I will tell you about such a team as chown. This article is suitable for both beginners and those who want to refresh their memory.

You had cases when you created a directory for some user or a file, but after creation, he could not write anything to the directory or read from it. For such cases, there is a command called chown, it serves to assign new owners to directories or files. In general, all files in Linux are associated with an owner and a group. Today we will look at popular options with the chown command.

Before moving on to the chown command, let's start by looking at the basic syntax.

The chown commands take the following form:

chown [OPTIONS] USER[:GROUP] FILE(s)

  • USER is the username of the new owner.
  • GROUP group name.
  • FILE(s) the name of one or more files or directories.

In the USER field, you need to specify the user whom we will make the owner of the file or directory. The GROUP field can be omitted, but if you do, then all users of this group will be owners. FILE(s) is the name of a file or directory.

 

All major options [OPTIONS]:

  • -c - verbose output of all changes performed.
  • -R  - recursive processing of all subdirectories;
  • -L - follow all symbolic links to directories;

 

Examples:

Let's say we have an inzhener directory and another app is created in it and it has the default owner root.


 

Now let's assign the owner of the postgres user to this directory, for this we will use the command:

$. chown postgres /inzhener

As you can see in the screenshot before, we had the owner root, and after the change it became postgres.


 

In this example, let's make not only the postgres user the owner, but also the postgres group, for this we will execute:

$. chown postgres:postgres /inzhener

And now we see that not only the postgres user, but also the postgres group has become the owner of the directory.


 

In the following example, we assign the owner of the postgres directory and the postgres group recursively, which means that we assign a new postgres owner to all nested directories.

$. chown -R postgres:postgres /inzhener


 

As a result, as you can see from the examples, the chown command is very simple and only allows you to change the owner and group. If you want to configure permissions on directories or files in more detail, then you need to use the chmod command for this. I will talk about it in the next article.

Thank you all, I hope my article was of some help to you.

 

SIMILAR ARTICLES