How to Access All Users in Linux Using Different Commands?
Last Updated :
08 May, 2025
Linux allows multiple users with their own custom setting and configuration to work together on the same system, even at the same time. It can even allow a particular user to access several sessions from different locations in order to work on the system. Below is a list of different commands to access the list of users in Linux:
Methods to Access All Users in Linux
Here are the various methods by which we can access all users in Linux.
1. less command
In less command, each local user's information is stored in the "/etc/passwd/" file, where each line in the file represents login information for one user. less command extracts user information from that file.
Syntax:
less /etc/passwd
Example:
The /etc/passwd
file is the core database for all local users on a Linux system. Each entry contains 7 colon-separated fields:
- Username (e.g.,
anshu
) - Password placeholder (
x
indicates encrypted passwords are stored in /etc/shadow
). - User ID (UID) – Unique identifier (e.g.,
1000
for regular users, 0
for root). - Group ID (GID) – Primary group identifier.
- GECOS – Optional user description (e.g., full name).
- Home directory (e.g.,
/home/anshu
). - Login shell (e.g.,
/bin/bash
).
2. getent command
getent command fetches user information from database configured in /etc/nsswitch.conf. file which also includes passwd database. Syntax:
getent passwd
Example:
- Lists all users, including those from external directories.
- Essential for debugging authentication issues in networked environments.
3. awk or cut command
If only username is what you want, use awk or cut commands to print only the field containing the username.
Syntax:
awk -F: '{print$1}' /etc/passwd
cut -d: -f1 /etc/passwd
getent passwd | awk -F: '{print$1}'
getent passwd | cut -d: -f1
Example:

4. compgen command:
compgen command also displays the name of all the users without any additional information.
Syntax:
compgen -u
Example:
Note: One can use compgen -c command to list all commands available if he/she is not the admin on a Linux system and don't have the sudo access.
5. who command
who command will print the info of the currently logged in user.
Syntax:
who
Example:
6. wc Command
wc command will get the total number of users on a particular linux system.
Syntax:
getent passwd |wc -l
Example:

Conclusion
Linux is a multi-user operating system that allows multiple users to work on the same system simultaneously, each with their own custom settings and configurations. Whether you need to list all users, find specific usernames, or check logged-in users, Linux provides multiple commands like less
, getent
, awk
, cut
, compgen
, who
, and wc
to retrieve user-related information.
Each command serves a different purpose—from displaying all system users (less /etc/passwd
), fetching users from databases (getent passwd
), extracting usernames (awk
, cut
), listing users (compgen -u
), checking active users (who
), to counting total users (wc -l
).
Also Read: 25 Basic Linux Commands For Beginners [2025]by
Similar Reads
How to Delete User in Linux | userdel Command Managing user accounts is an essential aspect of Linux system administration. Understanding how to delete a user in Linux is crucial, whether you need to remove an unused account, revoke access for a departing employee, or clean up your system for security reasons. Here, we will explore the 'userdel
5 min read
How to add User in Linux | useradd Command useradd is a command in Linux that is used to add user accounts to your system. It is just a symbolic link to adduser command in Linux and the difference between both of them is that useradd is a native binary compiled with the system whereas adduser is a Perl script that uses useradd binary in the
5 min read
How to execute commands remotely using SSH in Linux? Many times users need to work in remote systems. For which they have to log in to the remote server, execute certain commands and come out of that session. Is it possible to perform all these actions locally? Yes, it's possible using ssh client. In this article, we will see different ways of running
2 min read
How to Remove All Users From a Group in Linux? A group is a collection object in the Linux operating system, which associates certain properties and access control to all its members. It is an efficient way for a system administrator to manage Access Control for its users. Groups are an important tool for a system administrator to maintain many
6 min read
Difference Between su and su - Command in Linux As a new Linux user, you may always face confusion regarding the difference between `su` command and `su -` command. In Linux, the `su` command is used to switch to another user account. However, there are two variations of the `su` command: `su` and `su -` (su hyphen).Table of ContentWhat is Linux
6 min read
List out all the Shells Using Linux Commands When you're operating out of a Linux environment, the shell is your primary tool for interacting with the OS. It's your command interpreter â it translates what you type into what the OS can interpret and carry out. From basic operations like looking at files to running complex scripts, the shell ma
4 min read
How to Display the current Username in Linux | whoami Command Imagine you're working on your computer and forget who you're logged in as. In Linux, there's a special trick called "whoami" that's like asking "Hey computer, who am I right now?" This article explains how this simple command works and helps you remember who's in charge! Don't worry, it won't be fu
4 min read
Access Control Lists(ACL) in Linux Access Control Lists (ACLs) provide an extended, more flexible permission mechanism for Linux file systems, allowing administrators to set specific permissions for individual users or groups. This guide will walk you through the key ACL commands, options, and use cases.Why Use ACLs?Think of a scenar
4 min read
How to Add User to a Group in Linux A group in Linux is a way to put users with similar access and permissions in a collection. By using groups, an administrator can define access control and permissions for all the users belonging to that group. Without groups, the administrator would have to define roles for individual users however
7 min read
users command in Linux with Examples users command in Linux system is used to show the user names of users currently logged in to the current host. It will display who is currently logged in according to FILE. If the FILE is not specified, use "/var/run/utmp". "/var/log/wtmp" as FILE is common. Syntaxusers [OPTION]... [FILE]where,OPTIO
2 min read