bash Linux:如何从组名中获取组 ID?反之亦然?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29357095/
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 12:41:29  来源:igfitidea点击:

Linux: How to get group id from group name? and vice versa?

linuxbash

提问by Deadman

I want to retrieve group id of a particular group name. Is there a command in Linux/UNIX systems to do this? Also if I want to do it the other way - get group name from group id, is that also possible?

我想检索特定组名的组 ID。Linux/UNIX 系统中是否有执行此操作的命令?另外,如果我想以另一种方式进行 - 从组 ID 中获取组名,这也可能吗?

回答by kberg

# getent group 124
mysql:x:124:

# getent group mysql
mysql:x:124:

回答by Dixel

I saw herethat you can use the idcommand to get gid or uid from group name or username respectively.

我在这里看到您可以使用该id命令分别从组名或用户名中获取 gid 或 uid。

id -u username

and

id -g groupname