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.
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

As we can see each line of the output provides the user name, user id, user group, user shell, user home path etc.
Print Only Usernames
We can print only usernames by filtering other columns like below.
$cat /etc/passwd | cut -d : -f 1

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.
$ cat /etc/passwd | grep -v nologin

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.
$ cat /etc/passwd | grep "/home/" | awk -F':' '{ print $1}'

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.
How To Add User To A Group In Linux
$cat /etc/group

Print Only Group Names
We can print only group names by cutting other column like below.
$cat /etc/group | cut -d : -f 1
