How to use the chgrp command in Ubuntu Linux with examples

The article provides a tutorial on using the chgrp command in a Linux system, particularly the Ubuntu OS, to change group ownership of files and folders. Further, it highlights the use of different chgrp options such as -c, –changes or -R, –recursive. Examples demonstrate how to apply these commands in real scenarios.

This article describes steps to run the chgrp command to change the group ownership of files and folders on Linux filesystems.

The chgrp command is used by users to change the group ownership of files and folders on Linux filesystems.

Using the chgrp command on Ubuntu Linux is essential for users who want to change the group ownership of files and folders on the Linux filesystem.

The chgrp command provides users with the ability to assign and restrict access to files and directories, making it a crucial tool for managing security and file permissions.

Additionally, understanding how to use the chgrp command can help users work more efficiently on the command line, which is particularly useful for system administrators and developers who work with Linux servers and command-line interfaces.

About the chgrp command:

The chgrp command is used by users to change the group ownership of files and folders on Linux filesystems. It also allows superusers to change and restrict access to files and directories.

Like using your mouse and keyboard to add and remove users’ access from files and folders in the GUI. The chgrp is the way to do it on the command line.

Linux has three major groups which apply for permissions. These are:


User — These permissions apply to a single user with special file access. This user is called the owner.
Group — These apply to a single group of users accessing the file. This group is the owning group.
Other — These apply to every other user on the system. These users are known as others or the world.


When a file is created, the user is automatically assigned ownership. And the group becomes the user’s default group. However, you can use the chgrp command to change each file or folder group.

Syntax:

The syntax is the rule and format of how the chgrp command can be used. The syntax options can be reordered. But a straight format must be followed.,.

Below is an example syntax of how to use the chgrp command.

chgrp [OPTION]. GROUP FILE.

Options:

The command line options are switches or flags that determine how the commands are executed or controlled. They modify the behavior of the command. They are separated by spaces and followed after the command options.

Below are some options for the chgrp command:

    FILE.Replace FILE. with the file you want to change its ownership. If the file doesn’t exist, the command will fail and not execute..
-c, –changesUse the -c or –changes option to report only when a change is made
-f, –silent, –quietUse them -for –silent, –quiet to suppress most error messages
-R, –recursiveUse the -R or –recursive option to operate on files and directories recursively
-v, –verboseUse the -v or –verbose option to output a diagnostic for every file processed
-h, –helpdisplay this help message and exit

Examples:

Below are some examples of how to run and use the chgrp on Ubuntu Linux.

If you want to change the ownership of a file named Confidential.txt, to the group name Private, you run the commands below.

chgrp Private Confidential.txt

If you want to change the group ownership of all files and folders in the /office/files directory to the Staff group, you run the commands below:

chgrp -hR Staff /office/files

The commands above change the owning group of /office/files, and all sub-directories, to the group Staff.

If you’re not logged in as a root account, you may have to use the sudo command.

chgrp -hR Staff /office/files

You add the R option to change the ownership and group of an entire directory, including sub-directories.

When you run chgrp with the –help option, you’ll see the help text below:

Usage: chgrp [OPTION]. GROUP FILE.
  or:  chgrp [OPTION]. --reference=RFILE FILE.
Change the group of each FILE to GROUP.
With --reference, change the group of each FILE to that of RFILE.

  -c, --changes          like verbose but report only when a change is made
  -f, --silent, --quiet  suppress most error messages
  -v, --verbose          output a diagnostic for every file processed
      --dereference      affect the referent of each symbolic link (this is

That’s it!

Hope you like it, and please come back soon for more Ubuntu Linux commands!

Richard Avatar

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *


Exit mobile version