Suggest a StoryDo you have a news tip? We would like to hear from you.

Command Line | Change The Owner Of Files And Folders | chown

Spread the love

chown is a Unix/Linux command for changing files and folders ownership.chown become really handy if you want to change the owner for many files or folders using the command line.

As long as you have multiple user accounts available in your system along with your root account, you can the ownership of files and folders between user account, in case you want to make a certain user and group has the privileges of read, write or both in this file or folder.

Check the earlier post for changing files and folders permissions using the command line chmod Here.

Before we go any further make sure exactly which folders and files you are going to change the ownership for. because it might effect your currently running system.

[How To]: Check the current files and folders permissions and ownership

There are many different types of listing files and folders can help you to check many information about your files and folder you are currently navigating, such as modified date/time, file size, current owner, associated group, and more.

In this case we will use this command

ls -l

[How To]: change The File or The Folder ownership

In the first screenshot we see many files and folders listed with owner name called “linuxnov”, so here how we are going to change “install.php” file to root owner for example

chown command require root user privileges if you are going to changes files owned by other users or even root user.

sudo chown root filename

Now run list command with long listing option to view the current ownership.

[How To]: change The File or The Folder ownership and groups

We will use the same command we used earlier for in step 2 and will add a colon followed by the group name.

sudo chown root:root filename

Make sure you use an exist user account and group name.

[How To]: change ownership for a folder and all sub directories and files beneath it – Recursively

sudo chown -R root foldername

So this will change all files and folder beneath folder called modules to the ownership called root.

That’s it for now.

Spread the love

Leave a Reply