A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/linux-unix/how-to-access-all-users-in-linux-using-different-commands/ below:

How to Access All Users in Linux Using Different Commands?

How to Access All Users in Linux Using Different Commands?

Last Updated : 12 Jul, 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:

  1. Username (e.g., anshu)
  2. Password placeholder (x indicates encrypted passwords are stored in /etc/shadow).
  3. User ID (UID) – Unique identifier (e.g., 1000 for regular users, 0 for root).
  4. Group ID (GID) – Primary group identifier.
  5. GECOS – Optional user description (e.g., full name).
  6. Home directory (e.g., /home/anshu).
  7. 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:

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



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4