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.

-Advertisement-

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

-Advertisement-

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

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

-Advertisement-

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!

-Advertisement-
Divya Kiran Kumar
I'm the 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. I 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,632FansLike
361FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

Top 20 Git Commands with Practical Examples

If you are here reading this post, there is a high probability that you have heard or interacted with Github, and you now want to learn Git. Before we continue with showing you some of the cool Git commands, let's understand the difference between Git and GitHub.

Top 10 New Features in Linux Kernel 5.7

Linus Torvalds has announced the release of Linux Kernel 5.7 after seven weeks of development. The release announcement comes as a piece of exciting news as it brings a host of new features for the hardware manufacturers as well as the developers.

How to install CMake on Ubuntu

CMake is a cross-platform free and open-source software tool designed to build, test, and package the software. CMake uses a simple platform and compiler-independent configuration files to control the software compilation process.

How to install Lightworks on Ubuntu

Even though Linux may not get a native installer of video editing software like Adobe Premiere or Final Cut Pro, that doesn't mean there are no industry standards tools available. Lightworks is non-linear editing (NLE) video mastering app for Windows, Linux, and macOS. Installing it on Ubuntu is simple due to deb package availability.

How to install DaVinci Resolve on Fedora

Davinci Resolve is a professional application used for color correction, video editing, visual effects, and motion graphics. It is one of the extensively used software by movie industries located in Hollywood.

The 10 Best Programming Languages for Hacking

One of the significant entities we have in Cyber Security is Ethical Hacking (ETH). It is the process of detecting and finding flaws or vulnerabilities in a system that a hacker would exploit.

MUST READ

Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.
Elementary OS 5.1 Hera has received a point release with a handful of new features and bug fixes, and we will be reviewing the significant changes in this article. For those new to elementary OS, this Ubuntu-based Linux distribution uses their inhouse built Pantheon desktop environment and AppCenter.

Top 20 must-have apps for your Ubuntu PC

OK, this one is going to be a long one, so grab a cup of coffee and scroll through the best apps that we think are must-have for your Ubuntu PC. We have hand-picked each one of these considering the most common categories that suit an average Linux user.

Ubuntu 19.10 (Eoan Ermine) Beta Installation and 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.

CopyQ – Advanced clipboard manager for Linux

We have all had that moment when we copied a text, but we first needed another one, and in the process, lost the first one. If you're lucky, you can get it back quickly with a bit of work.

The 10 Best Programming Languages for Hacking

One of the significant entities we have in Cyber Security is Ethical Hacking (ETH). It is the process of detecting and finding flaws or vulnerabilities in a system that a hacker would exploit.