How to change group ownership of a file in the Linux system?
In this article, we will learn to add groups, delete groups, and
change the group ownership of a file, group of files, or directories.
We know that Linux is a multiuser operating system so every
file or directory belongs to an owner and group. To change ownership of files
or directories we use chown (change ownership) command and to change the group
ownership of files or directories we use the chgrp command.
The chgrp (change group) command is used to change the group
ownership of files or directories in the Linux/Unix operating system.
syntax
The general syntax of the chgrp command is as follow:
chgrp [OPTION]... GROUP FILE...
chgrp [OPTION]... --reference=RFILE FILE...
A brief description of options available in the chmod command:
|
Option |
Description |
|
|
1. |
-c, --changes |
Gives a diagnosis for all
the files that actually changed. |
|
2. |
-f, --silent, --quite |
It suppresses most of the
error messages. |
|
3. |
-v, --verbose |
Give a diagnosis for all
the processed files. |
|
4. |
-R, --recursive |
It changes file and
directories recursively. |
|
5. |
--help |
Displays a help message
and then exit. |
|
6. |
--version |
It gives info about the
version and then exits. |
How to add a group in the Linux operating system using a
terminal?
To add a group in the Linux system we need administrative
permission or sudo privilege. If we want to add a new group, we use the
addgroup command.
The general syntax of the addgroup command
$ sudo addgroup <group name>...
Suppose we have to add a new
group snow in the Linux system using the terminal.
$ sudo addgroup snow
How to remove group in the Linux operating system using the terminal?
To remove a group in the Linux system we need administrative
permission or sudo privilege. If we want to remove an existing group, we use
the groupdel command.
The general syntax of the groupdel command
$ sudo groupdel <group name>...
Suppose we have to delete a
existing group snow in the Linux system using the terminal.
$ sudo groupdel snow
After executing the above command the group snow will be deleted
from the system. Before deleting, the group must be available otherwise error will
be prompt.
To change the group ownership of a file using terminal, we use
the chgrp command in the Linux system
First, we will check that the file associated with which group.
To check this use the below command.
$ ls -l <file name>
The below output a just an example output.
-rw-rw-r-- 1 owner group 204800 Dec 28 14:04 file.txt
To change the group ownership of a file use the below command.
$ sudo chgrp snow file.txt
Conclusion: In this article, we learned to create a group, remove a group, change ownership of the group with available options in the chgrp (change group) command in the Linux system. To change ownership of files or directories the chown command is used in the Linux operating system.
Comments
Post a Comment