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 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,420FansLike
377FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

Getting Started with Linux Operating System

The Linux operating system brings forth a vibrant mix of features and security, making it the best alternative to macOS or Windows operating systems. In this post, we will give you a master guide on Getting started with Linux systems - taking you from a complete beginner to a level where you can begin testing the various Linux distributions available with much ease.

How to Create a Comprehensive Mail Server on Ubuntu

Postal is a free and open-source mail server used to send and receive emails. It comes loaded with tons of excellent features and functionalities, making it extremely popular among large organizations as well as in enterprise settings.

The 10 Best Linux Performance Monitoring Tools

Do you want to monitor the performance of your Linux system? Are you looking for some powerful performance monitoring tools to help you out? If you agree, it's your day as we have put together a detailed list of the ten best Linux performance monitoring tools.

How to Boot your Windows or Linux PC from a USB Drive

Sometime back, the process of installing an operating system required users to pop a bootable media disk into their DVD or CD drive and use it to boot the PC. But times have changed. Nowadays, the most common way of installing an OS is booting from a USB drive. The use of USB drives is further propelled by the current production of slim and lightweight laptops with no support for DVD/CD drives.

Python For Loop: Everything You Need to Know

Loops are one of the essential elements in any programming language, and Python is not an exception to it. Loops are used to repeat a statement or a block of statements multiple times. If there were no concept of loops in programming languages, we have to write each statement again and again for the number of times we want to execute it.

How to install LibreOffice on Fedora

If you are looking for a feature-rich and reliable Office Suite for your Fedora PC, then you have an excellent option at hand. LibreOffice, a free and opensource app, has stood the test of time and evolved into a beautiful alternative to Microsoft Office.

MUST READ

Buyers who wish to go for a machine that is based on Linux often show interest in Chromebooks due to the form factor and extended battery life capabilities. Although ChromeOS power these machines, users can still miss out on a more genuine Linux experience. For those who happen to agree, the new Lemur Pro by System76 might get some heads turning.
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.

13 ways to use the copy command in Linux (with examples)

Being a Linux user, copying files and directories is one of the everyday tasks that you have to carry out. It can be copying a file to make a backup or copy it to another partition, directory, or external storage drive.

Installing multiple Linux distros on a USB drive

A bootable Linux USB drive, which also referred to as a Live USB drive, is a drive containing files that enable a computer to boot into a specific Linux distro. It is most commonly used to test-drive various Linux distros before installing on the computer for use as a daily driver.

VIDEO: Linux Lite 4.8 Features and Desktop Tour

Linux Lite eases Windows 7 users transition to Linux much more comfortable by offering simple software like Team Viewer, VLC, Firefox, TimeShift backup utility, and a full Microsoft Office compatible office suite in LibreOffice.

VIDEO: MX Linux 19 Features and Desktop Tour

MX Linux is a Linux distribution based on Debian stable and using core antiX components. The distributions MX Tools is very popular among users and combined with other several ready-to-use tools, it is great for users who prefer to tweak their distro to their liking. In this video, we will take you through the features tour showing casing MX Linux 19.