Blog Post
How to List Users in Linux Using the Terminal
Commands

How to List Users in Linux Using the Terminal

Whether you have a particular reason why you need to know more about the users of your system or you are only curious, you can use a simple command to list users with registered accounts on your OS. Take a look at the easiest tutorial on how to list users in Linux.

How to List All Users in Linux

When you open the terminal, try typing the following:

less /etc/passwd

That will open the file that keeps the data about all the users on that Linux system.

Each account will have a separate line with info about their username, ID number, group ID, full name, home folder, and login shell.

If you do not need such comprehensive information, how about listing only the usernames? You can do that with the following line:

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

The system will now show usernames of all registered accounts and each of them will be in a separate line.

An Alternative Method of Listing All Users

If you do not want to use the above command for any reason, try the below line:

getent passwd

This command will order Linux to display the user information from the “etc/nsswitch.conf” databases. In essence, you will get identical information like when utilizing the “etc/passwd” file.

If you only need account usernames, you can also give additional instructions in the command:

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

Discover If a User Exists in Linux

What about using the reverse approach? Instead of listing all users, how about checking if a user with a particular username exists on the system.

Here is the command you can use to do that:

getent passwd username

If you get a blank screen, that means that the specified username does not exist in the system. However, if Linux finds a user with that username it will list complete information about them.

discover if a user exists in linux

What Is the Total Number of Users on Your System?

Checking the total user number may be a useful safety measure if you know how many accounts should be active. Here is the command you should use:

getent passwd | wc -l

Linux will display a number, and that will mark the total number of users on your system.

what is the total number of users on your system

How to List a Group of Users in Linux

Apart from listing particular users, you may want to list different groups, which you can do with the following command:

getent group

The system will immediately show extensive information about various groups on the screen.

You can also search a username across all groups with this command:

getent group | grep search_this

You can replace “search_this” with the username you are looking for, and the system will show the user and which group they belong to on the screen.

Wrap Up

That concludes our tutorial on how to list users in Linux, as well as checking the total user number and searching groups on your system. Remember, these commands work on any Linux-based system – just open the terminal and type the desired command from the ones mentioned in this guide.

Related posts
Leave a Reply

Required fields are marked *

Copyright © 2019 Blackdown.org. All rights reserved.