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:
You can also see all the groups on your system with this command:
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
Go right ahead and stay in your home directory. You can check the various files and their permissions with the following:
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:
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.
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.