Listing Users in Linux explained with examples

In this tutorial, we shall show you how to list the users, find a specific user, find the total number of users, and more on your Linux system.

Finding out the list of users on a Linux system is a common situation, especially for system administrators. We will show you how to do this in today’s tutorial.

Linux is a multi-user platform. It ensures that multiple users can use it without the need for a new installation. Linux handles applications securely. No user can access other user files without proper authentication access. The list of accounts is shown on the Terminal and helps manage.

Let’s get started.

How to list Users in Linux

There are many ways you can list users in Linux.

1. Using etc/passwd command

One of the easiest ways to access the list of users in Linux is to find that information in the /etc/passwd file. To check its data, you need to use either less or cat.

$ cat /etc/passwd | more

checking-list-in-Linux
Content of /etc/password

You should see a lot of lines being outputted on the Terminal. Each line is divided into seven fields using a colon delimiter. The sequence of information is as below.

  • User name
  • Encrypted password
  • UID: User ID number
  • GID: User’s group ID number
  • GECOS: User’s full name
  • User home directory
  • Login shell

All this information can be a little overwhelming and unnecessary. That’s why it is always a good idea to use the awk command only to display the username.

To do so, you need to use the following command.

awk - F: '{print $1}' /etc/passwd

user-name-show-etc-password
Showing only the name using awk command on etc/passwd file

You can also get the same result using the cut command.

cut -d: f1 /etc/passwd

For some reason, if the above command doesn’t work, then you need to use the following.

cut -d: -f 1 etc/passwd

2. Using the Getent command

You can also use getent command to display the list of users. In this case, it queries the passwd database, which is in the list of database configured in /etc/nsswitch.conf.

The command to list all the users using getent command is as below:

getent passwd

You can also use more or less command along with it to limit the output according to your window size.

showing-users-with-getent-command
Showing the list of users using the getent command

The output is precisely similar to the information contained in the etc/passwd file. If you want to access the LDAP database, then you need to provide the user authentication with LDAP.

You can also trim the output of the user’s list using the awk and cut command. The commands are as below for your ready reference.

$ getent passwd | awk -F: '{print $1}'
$ getent passwd | cut - d: - f 1

3. Finding a specific user

Getting a long list of users is not desirable in most cases. What if you want to search for a particular user? It is possible, and here is how.

To do so, you need to use the grep command and pipe it with the getent command.

For example, if we want to search for tuts user, then we can do it using the following command.

getent passwd | grep tuts

tuts-user-specifc
Finding a specific user using the grep a getent command

If there is no output, then it means that the user is not registered in the system. There is also a more straightforward command that lets the job done. In this case, you do not need to use the grep command.

getent passwd tuts

If you get a reply, then the user is present; if not, then there is no user with that specific name.

4. The total number of users in the system

If you are curious to know the total number of users in the system, then you can check it using the following command:

getent passwd | wc -l

total-user-getent
The total number of users

Here, we used the wc(word count) command to learn about the total number of users.

Conclusion

This leads us to the end of our tutorial on how to list users in Linux. Besides, we also learned how to find a specific user, and also to fish out the total number of users registered on a Linux system. Do you use the commands mentioned above for your daily job? What other tricks do you use? Do share with the rest of the FOSSLinux readers. Sharing is caring!

Divya Kiran Kumar
I'm Editor of FOSS Linux. I worked as a Software Engineer, before taking up blogging as my full-time job. I enjoy using Linux, and can't imagine anything else for my PC. Apart from writing for FOSS Linux, I enjoy reading non-fictional books. Sapiens was my favorite last read. Hope you enjoy reading and using this blog to enhance your Linux experience! Have a great day ahead!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

23,874FansLike
265FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

Application Launchers for Ubuntu
Ubuntu is one of the most used Linux distributions worldwide. It is also the reason why it has the maximum number of available programs for itself. Today we are going to talk about one category of those programs, the application launchers.
Ubuntu 19.10 beta overview
It may be early, but I've been looking forward to the release of Ubuntu 19.10 for some time now. As an impatient person, and promised readers in the FOSSLinux article announcing the release of Eoan Ermine that we would provide you a review of Ubuntu 19.10 Eoan Ermine - Beta.  So, here it goes.