📒 

Linux is very widely used in the field of server technology and development. One of the important aspects of Linux administration is the ability to view information about users registered in the system. In this article, we will look at various methods and commands to view users in Linux.

Method #1. Checking using the /etc/passwd file

One of the main sources of user information in Linux is the /etc/passwd file. This file contains records of users, their IDs, home directories, and shells used. You can use the cat or less command to view the contents of this file. Each line of the file represents a user record, with fields separated by colons. An example is shown here:

 

Method #2. Using the getent command

The getent command is used to retrieve records from databases, including user information from the /etc/passwd file. This allows you to more conveniently view the list of users.

getent passwd

Method #3. Using the cut command to extract usernames

If you only need to output usernames, you can use a combination of the cut and awk commands. 

getent passwd | cut -d: -f1

This command works by using the colon delimiter in the /etc/passwd file to extract the first field. This in turn contains the usernames that are displayed to you.

 

Method #4. Using the awk command to selectively display information

As you work with your server, you may need to limit the output to information about specific aspects of the user; you can use awk. For example, the following command will display the names and home directories of all users:

getent passwd | awk -F: '{print "Username: " $1 "\t Home Directory: " $6}'