Through this article, we will cover chown & how to use chown command in Linux or UNIX systems.
If you want to know about chmod and umask you read our below
Table of Contents
What is chown?
Chown stands for change file owner and group.
Chown command is used to change ownership of files and directories or folder in the system.
Now we will explain you what is ownership?, How you can use?
What is ownership?
In the chmod articles, we have explained to you that there are three types of file permissions
- User Permission
- Group Permission
- Other Permission
So, every file or directory has a specific owner and permissions by default, or you assign them.
User Permission (u):-
The user permission means when a single person or specific person has all kinds of rights to manage a file, and In other words, we also called the owner.
Like you have created a directory or file in a Unix-like system, then you will be the owner of a specific file.
Group Permission (g):-
The group permission means when a single group of the user has specific rights to manage a file, and In other words, we also called the owning groups.
A file is created or directory which is manage by owning group of users.
Other Permission (w):-
The other permission is like other users can also manage files or directory in a UNIX-like system, we also called this type of user as others or world permission.
Like you other users created a directory or file in a UNIX-like system, all the other system users have specific rights.
Type of permission
There are three types of permission that we can set on a file, and directories are as follows:
Read permission:- When the character is “-” then the file is not allowed to read, if the character is “r” then you can read the file.
Write permission:- When the character is “-” then the file is not allowed to do changes. If the character is “w”, you can make changes in the file.
Execute permission:– When the character is “-”, the file will not execute. If the character is “x”, then you can execute the file.
chown [OPTION]... [OWNER][:[GROUP]] FILE... chown [OPTION]... --reference=RFILE FILE...
So, now we will explain to you how to use the chown command to change the owner, group, and others with examples.
There are many options that you can use with chown to check more options type in the terminal:
How to use chown to change the owner of the file?
If you want to change ownership to certain users, then you have to type in the terminal like
chown [username] [filename]
In my case file owner is shen.
Now I’ll change owner to root using below command
$chown root nameofile.txt
Current owner of file is root previously it was shen.
How to use chown to change the group of the file?
If you want to change the owner to certain groups, then you have to type in the terminal like:
chown :[group-name] [file-name]
Now we will show In my case file group is shen.
So we will change group shen to root:
$ sudo chown :root nameofile
Curent group ownfile is root not shen.
How to use chown to change both owner and group together?
From the above examples, we have changed both owner and group to revert back to the same owner and groups.
chown [new-owner]:[new-group] [file-name]
This is my current owner and group is root.
Now we will change owner and group both:
$ sudo chown shen:shen nameofile
Through chown command we can change owner, groups and others.
To change groups we can use both chgrp and chown.
Whenever you want to change the owner of a file or directories, you have to use sudo before chown.
The owning group file can be change roots and the owner of groups.
A man with a tech effusive, who has explored some of the amazing technology stuff and exploring more, While moving towards, I had a chance to work on Android Development, Linux, AWS, DevOps with several Open source tools.
One of my life mottos “Always be lifelong Students.”