![linux 列出用户组](https://i-blog.csdnimg.cn/blog_migrate/2fc9243da449b81f936c300a5fc7c7e5.png)
linux 列出用户组
Users and group files are important for Linux. Normal users will interact with Linux systems by using credentials provided in the user ad group file.
用户和组文件对于Linux很重要。 普通用户将使用用户广告组文件中提供的凭据与Linux系统进行交互。
打印名为passwd的用户文件 (Print User File Named passwd)
We can get content of the user file like below. This file provides usernames home directories and shell information.
我们可以获取用户文件的内容,如下所示。 该文件提供用户名主目录和外壳程序信息。
$cat /etc/passwd
![Print User File Named passwd](https://i-blog.csdnimg.cn/blog_migrate/6438b525ed81c4dd463901706a436c89.png)
As we can see each line of the output provides the user name, user id, user group, user shell, user home path etc.
我们可以看到输出的每一行都提供了用户名,用户ID,用户组,用户外壳程序,用户主目录路径等。
仅打印用户名 (Print Only Usernames)
We can print only usernames by filtering other columns like below.
我们可以通过过滤以下其他列来仅打印用户名。
$cat /etc/passwd | cut -d : -f 1
![Print Only Usernames](https://i-blog.csdnimg.cn/blog_migrate/c4593cc9c663bd420e768033f51b2332.png)
打印已登录的用户(Print Users Who Have Login)
By default normal users will login to the Linux box. But in some cases service users do not need to login Linux system. This is also a security measure. We can list users who do not have login right with the following command. This login information is stored in the /etc/passwd
file.
默认情况下,普通用户将登录Linux框。 但是在某些情况下,服务用户不需要登录Linux系统。 这也是一种安全措施。 我们可以使用以下命令列出没有登录权限的用户。 此登录信息存储在/etc/passwd
文件中。
$ cat /etc/passwd | grep -v nologin
![Print Users Who Have Login](https://i-blog.csdnimg.cn/blog_migrate/4cd60450cf1b580a90bbd15749631dd1.png)
打印具有家庭目录的用户(Print Users Who Have Home Directories)
We can print only users who have home directories in /home. This command will first look in to the passwd to list users how have /home and then print only user names from result.
我们只能打印在/ home中具有主目录的用户。 此命令将首先在passwd中列出用户的/ home权限,然后仅打印结果中的用户名。
$ cat /etc/passwd | grep "/home/" | awk -F':' '{ print $1}'
![Print Users Who Have Home Directories](https://i-blog.csdnimg.cn/blog_migrate/31fcf9f70ed8c4daf40e704151ce73d9.png)
打印组文件(Print Group File)
Linux users have primary and secondary groups. These group names are stored in the /etc/group
file. We can print this group information and assigned user with cat command. For more details read following tutorial.
Linux用户具有主要和次要组。 这些组名存储在/etc/group
文件中。 我们可以使用cat命令打印此组信息并分配用户。 有关更多详细信息,请阅读以下教程。
How To Add User To A Group In Linux
$cat /etc/group
![Print Group File](https://i-blog.csdnimg.cn/blog_migrate/0facdbf5e8056a2d0b986faf200f23a9.png)
仅打印组名(Print Only Group Names)
We can print only group names by cutting other column like below.
我们可以通过如下切割其他列来仅打印组名称。
$cat /etc/group | cut -d : -f 1
![Print Only Group Names](https://i-blog.csdnimg.cn/blog_migrate/b2963e90389c5c321889385498a77371.png)
linux 列出用户组