How to change the owner of a folder in Linux

owner folder

When a system is used by multiple users, or by one user but you need to change the owner directory, like to some program's account, etc., then you should know how to change owner of a folder in linux. There are several methods to do it, as I will explain to you in this short tutorial, and you will be able to follow it step by step to make it very easy, even if you are a beginner in the Linux world. As you can see, it is not very complicated.

To perform this operation you will need privileges, so you must execute the following commands by prepending sudo or being root, as you prefer. Well, having said that, let's use the chown command, which comes from change owner, and is used precisely to change the group or owner of any file or folder. The general syntax of this command is as follows:

chown [options] user[:group] /file

That is, you will have to add the options you need, replace user with the username (you can also use the user ID if you prefer) to which you want to put it, and followed by a colon and the new group (although this is optional ) and finally indicate the file or directory you want to change ownership. Let's see a practical example of use. Imagine that you have a directory called /home/manolito/test/ that you want to change from user owner manolito to owner named agus. In this case, it would be as simple as running this command:

sudo chown agus /home/manolito/prueba/

It would be that easy. And if you want it to be recursive, so that it affects subdirectories as well, then you can use the -R option between chown and agus in this case. For example, it would be something like this:

sudo chown -R agus /home/manolito/prueba/

As you can see, it is quite easy to change the owners of a directory or any system file with this command.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.