Linux queries all members within the group based on the group name

Source: Internet
Author: User

Currently, there is no command to query a team member directly based on the group name in Linux.

There are two ways that the system provides a way to find relationships between group members and groups.

One is to find the/etc/passwd and/etc/group directories, and find the members within the group in/ETC/PASSWD based on the ID of the group in the/etc/group directory.

The other is: through the groups command, according to team members to find the group belongs to

I use the grep and cut commands to find out the function of the group member through the name of the team, the command is as follows

# gid= ' grep ' group name '/etc/group | Cut-d ': '-f 3 ' && grep '. *:x:[0-9]*: $gid "/etc/passwd |cut-d ': '-F 1

Description

This sequence of commands is separated by && (&&: The command of the current polygon is correct, the subsequent command executes)

&& Previous command: First, according to the group name with grep from the/etc/group query out the group name which line of information, and then use the Pipeline command cut detect GID, then the GID assigned to the variable.

&& after a paragraph of command: first in grep through the "regular match plus gid" from the/etc/passwd to find out the group of each member of the information (a behavior of a member), and then cut the user name "cut" out.

Linux queries all members within the group based on the group name

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.