如何使用 apt-get 在 Ubuntu Linux 上安装 ssh
2024年3月29日操作方法:在 Unix/Linux 中 Bash 提取文件名和扩展名
2024年3月29日我是一个 Linux 和 Unix 系统的新用户。如何在 Linux 或类 Unix 系统上列出组的成员?
在 Linux 和类 Unix 系统上有多种方法可以获取此信息。
会员指令详情 | |
---|---|
描述 | 显示群组成员 |
类别 | 用户信息 |
难度级别 | 简单的 |
根权限 | 是的 |
操作系统兼容性 | Alma • Alpine • Arch • CentOS • Debian • Linux • Mint • RHEL • Rocky • Stream • Ubuntu |
美东时间。阅读时间 | 2分钟 |
目的
输出组的成员。
句法
基本语法如下:
members groupNameHere
members [options] groupNameHere
默认情况下,您的系统上可能未安装members命令。因此,在 Alpine Linux 上使用apk 命令,在 RHEL 和 co 上使用dnf 命令/ yum 命令,在 Debian、Ubuntu 和 co 上使用apt 命令/ apt-get 命令,在 SUSE/OpenSUSE 上使用 zypper 命令,在 Arch Linux 上使用 pacman 命令来安装成员。
在 Debian/Ubuntu Linux 上安装成员
尝试apt-get 命令或apt 命令:
sudo apt install members
[sudo] password for vivek: Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: members 0 upgraded, 1 newly installed, 0 to remove and 7 not upgraded. Need to get 9,320 B of archives. After this operation, 34.8 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu focal/universe amd64 members amd64 20080128.1+nmu1build1 [9,320 B] Fetched 9,320 B in 1s (10.8 kB/s) Selecting previously unselected package members. (Reading database ... 260965 files and directories currently installed.) Preparing to unpack .../members_20080128.1+nmu1build1_amd64.deb ... Unpacking members (20080128.1+nmu1build1) ... Setting up members (20080128.1+nmu1build1) ... Processing triggers for man-db (2.9.1-1) ...
members command examples
Buy default members command display all group members on one line. Open the Terminal application and type the following command to display members of ‘webmaster’ group:
$ members webmaster
In this example, six users are output: webadmin, raj, vivek, archana, sai, and sayali. You can count total users in a group called members using wc command:
$ members webmaster | wc -w
Sample outputs:
6
Display only primary group members
Pass the -p option:
$ members -p webmaster
Display only secondary group members
Pass the -s option:
$ members -s webmaster
We can send two lines to screen. First line is primary members, second line is secondary members. Pass the -t option as follows:
$ members -t sudo
NOTE: This always displays two lines, even if there are no members at all.
Query /etc/group file
Use the following grep command or egrep command to query /etc/group as follows:
# look for members of 'webmaster' and 'sudo' group under Linux grep '^webmaster' /etc/group grep '^sudo' /etc/group
Use getent command to query groups
使用以下 getent 命令查询组数据库(例如基于文件或 NIS 的组数据库):
$ getent group | grep '^webmaster'
## no need to use the grep command. Pass the group name as CLI arg ##
$ getent group {group-name-here}
$ getent group sudo
$ getent group webmaster
加起来
您了解了 Members 命令,该命令将空格分隔的辅助成员名称列表发送到屏幕。
也可以看看
使用 help 命令或 man 命令查看以下手册页:
man 5组 man 1 getent man 1 grep man 1成员