Change Ownership Of Files And Folders

Today, we’ll be covering how to change ownership of files and folders. This is a pretty basic task and one every Linux user should know. This needn’t be terribly complicated, so this article will explain all you really need to know about changing ownership of files and folders.

When dealing with file management, permissions are important. It’s a security matter and a usability matter. You can assign various file and folder permissions, such as read and write permissions, a subject for a different article. However, files and folders all should have owners – owners who can do anything they want with the file or folder.

Curiously, your account should not always be the owner. While maybe not all that intuitive, you shouldn’t have ownership of all the files. This is why you have to use elevated permissions to perform certain tasks. This is to keep things segmented and secure.

Remember, Linux is designed to be a multi-user operating system. That’s not just human users, but different processes and applications may also be associated with users. For example, look at all the users on your system by running the following command in your terminal emulator:

getent passwd

You can also see all the groups on your system with this command:

getent group

Obviously, if a user is a member of a group they share permissions with that group. Files also only have one owner and one associated group, of course. So, if you want two people to have control over a file, one way to do that would be to make sure they’re both members of the same group. There’s all sorts of creative things you can do with permissions. This article will be covering just one aspect, it’ll be about how you can …

Change Ownership Of Files And Folders:

Like oh so many of these articles, this one requires an open terminal. You can do so using only your keyboard – just press CTRL + ALT + T and your default terminal should open.

Go right ahead and stay in your home directory. You can check the various files and their permissions with the following:

ll

The output of that command will show you the user and group, with the two being listed in that order as in the image below:

See? I even gave you handy arrows. The order is owner:group, to repeat myself.

To change the owner, the format is:

sudo chown <new_owner> /path/to/file/or/folder

To change the group, the format is:

sudo chgrp <new_group> /path/to/file/or/folder

If you want to recursively take ownership, you need the -R flag. For that, you’d want something that looks a bit like this:

sudo chgrp -R <new_group> /path/to/file/or/folder/*

You can actually just use chown to change both the owner and group at the same time. You’ll most often do this with your own user and group, so I’ll show the command that way:

sudo chown kgiii:kgiii /path/to/file/or/folder/

As you can guess, the -R flag will work there and an asterisk will cover all the files and folders within that directory. Obviously, this applies to folders and not to files.

Closure:

There you have it. You have yet another article and this one has hopefully taught you how to change ownership of files and folders. It may not be one of the most interesting articles, but it’s a skill you’ll eventually want to have and another tool for your Linux toolbox. 

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

KGIII

Retired mathematician, residing in the mountains of Maine. I may be old and wise, but I am not infallible. Please point out any errors. And, as always, thanks again for reading.

Recent Posts

Short: The Halt Command

Today's article is intentionally short because we're simply going to learn about the basics of…

2 days ago

Installing Flatpaks In Linux

Today we're going to have a pretty easy article where you'll learn about installing Flatpaks…

4 days ago

A Quick Look At The Shutdown Command

This is going to be just a quick article about a command many of you…

6 days ago

Setting Up Coding Environments on Linux for Educational Use

With so many strong attributes, such as robustness and flexibility, Linux stands as a powerful…

1 week ago

View Detailed Hardware Information

There are many tools for showing your hardware information and today we'll get to view…

1 week ago

How To: Install Wine In Lubuntu

Today's article isn't going to be complicated or long as we are going to cover…

2 weeks ago