View All users in a user group in Linux

Source: Internet
Author: User


In Linux, all users under a user group are searched online, and many copy articles are displayed. groups displays the user group of the currently logged-on user, and there is no user list of this user group. In practice, you can use the following method to view all users in a user group: information about groups in the system is stored in the/etc/group file, put user information in the/etc/passwd file. Now I want to view all users in a group named "Plants. First, you must know the group id, that is, gid. Run the command: grep 'plants'/etc/group www.2cto.com and the result is: Plants: x: 1003 indicates that gid is 1003 (this group is 1003 on my computer, other computers may also be other numbers ). Then, in/etc/passwd, find the user whose group number is 1003. You can check this file with cat/etc/passwd and find that the fourth column is gid (separated ). Next, enter: awk-F ":" '{print $1 "\ t" $4}'/etc/passwd | grep '000000' ": ":" is used as the separator (":" is used as the Separator in/etc/passwd); print; $1 and $4 represent the first and fourth columns, respectively, and username and group number; \ t indicates a tab; grep '123456' indicates that 1003 rows are taken out. In this way, all users in a group can be displayed.
 

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.