bash 如何在 Ubuntu 中更改文件的组所有权?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21865940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 09:36:55  来源:igfitidea点击:

How do I change the group ownership of a file in Ubuntu?

linuxbashubuntuaccess-rights

提问by PuchuKing33

I have a little question on how to change the group owner of a file. At the moment the group of the file is the same as my user name but I want to change it so another user can access that same file and read/write to it.

我有一个关于如何更改文件的组所有者的小问题。目前,文件组与我的用户名相同,但我想更改它,以便其他用户可以访问同一个文件并对其进行读/写。

回答by Jens

The syntax would be

语法是

chown user:group file ...

This usually (=when you're not root) only works as long as you are a member of the same group (since otherwise by chown'ing files you could exceed the other user's disk quota).

这通常(=当您不是时root)仅在您是同一组的成员时才有效(因为否则通过 chown'ing 文件您可能会超过其他用户的磁盘配额)。

If you both are in the same group you could also allow write access with

如果你们都在同一个组中,你也可以允许写访问

chmod g+w file

As above this will allow all members of groupwrite access.

如上所述,这将允许所有成员进行group写访问。

If you do not share a common group, all you can safely do is to allow read access to the file so the other user can make a copy of it and edit his/her copy.

如果您不共享一个公共组,您可以安全地做的就是允许对该文件进行读取访问,以便其他用户可以制作该文件的副本并编辑他/她的副本。

回答by Agis

You can do it using chown:

您可以使用chown

$ chown :friends myfile

This would change the group of myfileto friends.

这会将 的组更改myfilefriends

回答by Martin

Also don't forget to change the file permissions to 660 that will give read, write, permission for the owner ( you ) and read, write permission for the new group.

另外不要忘记将文件权限更改为 660,这将为所有者(您)提供读、写权限,并为新组提供读、写权限。

Example:

例子:

-rw-r-----  1 martin martin          0 Feb 18 21:41 test

$ chown martin:newgroup test

$ chmod 660 test 

-rw-rw----  1 martin newgroup          0 Feb 18 21:41 test