0
0
Linux-cliHow-ToBeginner · 3 min read

How to List Users in Linux: Simple Commands Explained

To list users in Linux, you can use the cat /etc/passwd command which shows all user accounts. For a cleaner list of usernames only, use cut -d ':' -f 1 /etc/passwd to extract just the user names.
📐

Syntax

The main command to list users is cat /etc/passwd. This file contains all user account information. Each line represents one user with fields separated by colons.

To get only usernames, use cut -d ':' -f 1 /etc/passwd. Here, -d ':' sets the colon as the delimiter, and -f 1 selects the first field (the username).

bash
cat /etc/passwd
cut -d ':' -f 1 /etc/passwd
💻

Example

This example shows how to list all usernames on the system by extracting the first field from /etc/passwd.

bash
cut -d ':' -f 1 /etc/passwd
Output
root bin daemon adm lp sync shutdown halt mail operator games ftp nobody systemd-network systemd-resolve systemd-timesync messagebus _apt lxd uuidd dnsmasq sshd user1 user2
⚠️

Common Pitfalls

One common mistake is trying to list users with commands like ls /home which only shows home directories, not all users.

Another is reading /etc/passwd without understanding its format, leading to confusion about fields.

Also, some system users do not have home directories and may be missed if you rely on directory listings.

bash
ls /home
# This only lists home directories, not all users

# Correct way:
cut -d ':' -f 1 /etc/passwd
Output
user1 user2 # Correct output: root bin daemon adm lp sync shutdown halt mail operator games ftp nobody systemd-network systemd-resolve systemd-timesync messagebus _apt lxd uuidd dnsmasq sshd user1 user2
📊

Quick Reference

  • cat /etc/passwd: Show all user account details.
  • cut -d ':' -f 1 /etc/passwd: List usernames only.
  • ls /home: Lists home directories, not all users.

Key Takeaways

Use cat /etc/passwd to see all user account info on Linux.
Extract usernames only with cut -d ':' -f 1 /etc/passwd.
Don't rely on ls /home to list all users; it shows only home directories.
System users may not have home directories but appear in /etc/passwd.
Understand the colon-separated format of /etc/passwd for accurate user info.