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/
仅详细输出组所有权更改(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/
翻译自: https://www.poftut.com/change-group-ownership-of-files-and-directories-with-chgroup-in-linux/
linux修改文件的所有权