linux修改文件的所有权_如何在Linux中使用chgroup更改文件和目录的组所有权?

linux修改文件的所有权

linux修改文件的所有权

Linux provides different tools for the similar or same functionality. chgrp  is the shortcuts for change group where used to change files group ownership. In this tutorial we will look different uses cases for chgrp  and examples. chgrp provides similar functionality to chown

Linux为相似或相同的功能提供了不同的工具。 chgrp是更改组的快捷方式,用于更改文件组所有权。 在本教程中,我们将探讨chgrp和示例的不同用例。 chgrp提供与chown类似的功能

句法(Syntax)

Syntax is simple where we provide options , group name and files in a row.

语法很简单,我们可以连续提供选项,组名和文件。

chgrp OPTION GROUP FILES

变更档案群组 (Change File Group)

We will start with a simple example where we will just just given file group. In this example we will change file named test  to the group named root. We generally need root  privileges in order to change group. In this example we will use sudo to get root privilege.

我们将从一个简单的示例开始,在该示例中,我们仅给出文件组。 在此示例中,我们将名为test文件更改为名为root的组。 我们通常需要root特权才能更改组。 在此示例中,我们将使用sudo获得root特权。

$ sudo chgrp root test

递归更改文件组 (Change File Group Recursively)

Another useful use case for chgrp  is changing group ownership recursively. We will use -r option for this operation.  We will change the group to the ismail  in the directory named /home/ismail recursively.

chgrp另一个有用的用例是递归更改组所有权。 我们将使用-r选项进行此操作。 我们将组更改为ismail在指定的目录/home/ismail递归。

$ sudo chgrp -R ismail /home/ismail/

详细更改文件组 (Change File Group Verbosely)

While changing group we may need more information about the operation. We call this as verbose mode. We can see operations verbosely with the -v option like below. In this example we will change directory named /home/ismail/.local  into group named ismail  recursively and print operations verbosely. We can see that if current file or folder is all ready assigned to the group we want to change we will get a message retained as

在更改组时,我们可能需要有关该操作的更多信息。 我们称其为冗长模式。 我们可以使用-v选项详细查看操作,如下所示。 在此示例中,我们将递归地将名为/home/ismail/.local目录更改为名为ismail组,并详细打印操作。 我们可以看到,如果当前文件或文件夹已经准备好分配给我们要更改的组,我们将收到一条消息, retained as

$ sudo chgrp -R -v ismail /home/ismail/.local/
Change File Group Verbosely
Change File Group Verbosely
详细更改文件组

仅详细输出组所有权更改(Verbose Output Only Group Ownership Change)

We may want to see verbose output only if the group ownership of a file or directory is changed. In this situation we can use -c option. We will use previous example but only show changed files and folder. As we can see changed files will annotated with from root to ismail which means groups ownership is changed from root to ismail.

仅当更改文件或目录的组所有权时,我们才可能希望看到详细的输出。 在这种情况下,我们可以使用-c选项。 我们将使用前面的示例,但仅显示更改的文件和文件夹。 如我们所见,更改后的文件将由from root to ismail注释from root to ismail ,这意味着组的所有权已从root更改为ismail。

$ sudo chgrp -R -c ismail /home/ismail/.local/
Verbose Output Only Group Ownership Change
Verbose Output Only Group Ownership Change
仅详细输出组所有权更改
LEARN MORE  How To Chown Recursively In Linux?
了解更多如何在Linux中递归地?

翻译自: https://www.poftut.com/change-group-ownership-of-files-and-directories-with-chgroup-in-linux/

linux修改文件的所有权

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值