In advance of commencing, let us see the ls -l command output, which will provide us info on file and listing permissions.
As you can see in the user’s house listing named Linux, there is a file named linuxhintfile and a listing named linuxhintdir. As you can see in the next and 3rd columns, the owner and group for both file and listing are linux.
Let’s say we want to adjust the consumer possession from the consumer linux, and make the user named linuxhint owner of the linuxhintfile file whilst leaving the team as linux.
The proper syntax is demonstrated down below to improve the person ownership of a file without having influencing its group.
As you can see in the graphic above, right after running ls -l yet again, we can see the person ownership changed from linux to linuxhint although the team remains the exact.
This next instance exhibits how to use the chown command to change the two person and group possession of the same file (linuxhintfile). The syntax is identical to the prior instance, with the big difference that a colon adopted by the group identify will have to be extra just after the username, as shown beneath.
In my case, I want to change the user and team possession of the linuxhintfile to the root consumer and root team, so I kind the following.
[cc lang=”text” width=”100%” height=”100%” escaped=”true” theme=”blackboard” nowrap=”0″]
chown root:root linuxhintfile
As you can see now, both equally the consumer and group ownership had been altered to root.
It is crucial to note that you don’t truly have to specify the group if you want to adjust equally person and group ownership to the exact same user. In such a case, you only want to variety the person followed by a colon with out a team, and the group will automatically alter to the very same as the new operator. This usually means if you form
In the example down below, both of those consumer and team will have to modify from root:root to linuxhint:linuxhint even however we didn’t form the group, just simply because we added the colon just after the username.
chown linuxhint: linuxhintfile
As you can see, equally person and group ownership ended up improved to linuxhint.
Transforming listing possession demands the similar syntax and calls for employing a flag if you want to change the ownership recursively, like subdirectories and documents contained in the directory.
Let’s see the directories, subdirectories, and their existing possession.
As you can see, we have a listing named linuxhintdir, whose owner is the linux consumer, and the team is the linux group. Within there is a subdirectory named linuxhintsubdir whose owner and group are the root.
In advance of likely with the recursive permissions, let us see what occurs if we adjust the linuxhintdir possession without the need of flags. In the case in point down below, I will modify the user and team ownership of linuxhintdir from linux to linuxhint.
chown linuxhint: linuxhintdir/
As you can see, the linuxhintdir ownership was adjusted efficiently to linuxhint. But the linuxhintsubdir subdirectory user and group remains root.
So, how to change the ownership recursively, together with subdirectories and subfiles?
For this, you only require to add the -R (Recursive) flag.
The adhering to illustration reveals how to alter the possession recursively for the linuxhintdir directory and its information and subdirectories. As proven previously, the primary directory consumer and group belong to linuxhint, and the subdirectory consumer and group belong to root.
The command down below recursively adjustments person possession to the user named linux and the linuxlat team.
chown -R linux:linuxlat linuxhintdir/
As you can see now, the listing possession was transformed and its content material which is what the -R flag does.
The adhering to state of affairs points out how to recursively modify ownership of all files and directories belonging to a certain consumer.
In this new state of affairs, as you can see in the pursuing photograph, we have the major listing linuxhintdir, which belongs to the user named linux, and the team linuxlat. The subdirectories and files inside of belong to users named linux, root, and linuxlat, groups named linuxlat, linux, and linuxhint.
Now let us say we want to change the consumer and group possession only of information/directories belonging to a certain consumer. In this situation, we will give the primary listing and all data files and subdirectories belonging to the consumer named linux to the person named linuxhint.
For this, we want to employ the -R flag described just before since we want to change permissions recursively. Moreover, we require to put into action the –from= solution adopted by the recent owner username (and/or team if required), the new consumer who will have the data files and directories., as proven in the image below.
chown -R –from=linux linuxhint: linuxhintdir/
As you can see, all information belonging to the user named linux now belong to the consumer named linuxhint. In this way, we adjust the possession of many documents belonging to a unique consumer with a one command.
Managing documents and directories possession effectively is a need to for any Linux person working with shared assets. As you can see, the commands are very very simple to discover and use.
You can get additional facts on chown at https://linux.die.web/person/1/chown. Also, you may be interested in reading Setuid, setgid, and sticky little bit spelled out.
I hope this tutorial describing how to use the chown command in Linux was useful. Maintain next this site for supplemental Linux ideas and tutorials.