Loading…
Warp is now open-source Learn more
Loading…
In Unix-like operating systems, the /etc/passwd file is a text-database that stores essential information about user accounts such as their username, groups, home directory, and more.
To get the full list of users registered on the system, you can display this file using the cat command as follows:
$ cat /etc/passwdWhich will produce a similar output:

Each line of the /etc/passwd file defines a user account and consists of 7 fields separated by colons (:):
username:password:uid:gid:description:home:shellWhere:
You can learn more about managing user accounts by reading our other article on how to create a user in Linux.
To get the list of user accounts defined in the /etc/passwd file as well as other configured user databases such as LDAP (Lightweight Directory Access Protocol) or NIS (Network Information Service), you can use the getent passwd as follows:
$ getent passwdNote that the output of this command is similar to the format of the /etc/passwd file.
While both cat /etc/passwd and getent passwd provide the list of user accounts, they might include additional information you don’t necessarily need every time. Linux offers powerful tools like cut and awk to filter and extract specific details from the output.
To only retrieve the list of usernames registered on the system without any additional information, you can use the following cut command:
$ cut -d: -f1 /etc/passwdWhere:
For example:
$ cut -d: -f1 /etc/passwd
root
daemon
bin
sys
www-data
nobody
johndoeIf you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Suggestions feature:

Entering linux list user names only in the AI command search will prompt a command that can then be quickly inserted into your shell by doing CMD+ENTER.
To retrieve the list of usernames registered on the system with Bash as their login shell, you can use the following awk command:
$ awk -F: '$7=="/bin/bash" {print $1}' /etc/passwdWhere:
Note that you can easily adapt this command to filter usernames based on any shell by replacing /bin/bash with the path of the desired shell (e.g., /bin/sh).
For example:
$ awk -F: '$7=="/usr/sbin/nologin" {print $1}' /etc/passwd
daemon
bin
sys
www-data
nobodySimilar to the /etc/passwd file, the /etc/group file is a text-based database used for managing user accounts and group memberships.
To get the full list of groups and their related users, you can display this file using the cat command as follows:
$ cat /etc/groupWhich will produce a similar output:

Alternatively, you can use the following getent command to also include group entries from external sources such as NIS or LDAP:
$ getent groupEach line of the /etc/group file defines a group and consists of 4 fields separated by colons (:):
group:password:gid:usernamesWhere:
To get the list of groups a user is a member of, you can use the groups command as follows:
$ groups <username>Where:
Which will output the list of groups in the form of a list separated by a space character.
For example:
$ groups johndoe
johndoe : johndoe sudoTo get the list of users with sudo access (i.e., root privileges), you can use the getent command as follows:
$ getent group sudoFor example:
$ getent group sudo
sudo:x:27:johndoeYou can learn more about sudo users by reading our other article on how to add a user to sudoers in Linux.
Linux offers various means to monitor system activity and check which users are currently logged in or have active processes.
To display information about currently logged in users, including the login name, tty name, date and time of login, you can use the who command as follows:
$ whoFor example:
$ who
john ttys001 Mar 24 11:00
alice ttys002 Mar 24 11:33To display information about the activity of currently logged in users, including their login name, the terminal name, the host from which the user logged in, the time since the user last typed anything, and the name and arguments of the current process, you can use the w command as follows:
$ wFor example:
$ w
USER TTY FROM LOGIN@ IDLE WHAT
john s002 - 11:33 7 nodeThis command looks through the wtmp file and prints a historical record of login events on your Linux system. This can be pretty helpful when you want to track down specific user logins or for security audits. You can use the command as follows:
$ lastFor example:
$ last
john ttys000 Sat Mar 24 08:21 still logged in
alice ttys000 Thu Mar 22 16:40 - 16:40 (00:00)Comments will help make your scripts more readable
Via command line arguments and prompting users for input
Use cURL to send data to a server
Learn how to upload a file to FTP, SFTP servers, Artifactory, and AWS S3 using the curl command.
Learn how to copy directories and their content in Linux using the cp command with options like -r for recursive copying, -i for interactive mode, and -a for preserving attributes.
Learn how to manually and automatically create and list groups in Linux.
Learn how to output the size of directories and subdirectories in a human-readable format in Linux and macOS using the du command.
Learn how to count files and folders contained in directories and subdirectories in Linux using the ls, find, and wc commands.
Learn how to output the list of open TCP and UDP ports in Linux, as well as their IP addresses and ports using the netstat command.
Learn how to filter and format the content of files and the output of commands in Linux using the awk command.
Learn how to recursively create nested directories using the mkdir command, Bash scripts, and Python scripts.
Learn how to remove local and remote user accounts and associated groups and files in Linux using the userdel and deluser commands.
$ cat /etc/passwdusername:password:uid:gid:description:home:shell$ getent passwd$ cut -d: -f1 /etc/passwd$ cut -d: -f1 /etc/passwd
root
daemon
bin
sys
www-data
nobody
johndoe$ awk -F: '$7=="/bin/bash" {print $1}' /etc/passwd$ awk -F: '$7=="/usr/sbin/nologin" {print $1}' /etc/passwd
daemon
bin
sys
www-data
nobody$ cat /etc/group$ getent groupgroup:password:gid:usernames$ groups <username>$ groups johndoe
johndoe : johndoe sudo$ getent group sudo$ getent group sudo
sudo:x:27:johndoe$ who$ who
john ttys001 Mar 24 11:00
alice ttys002 Mar 24 11:33$ w$ w
USER TTY FROM LOGIN@ IDLE WHAT
john s002 - 11:33 7 node$ last$ last
john ttys000 Sat Mar 24 08:21 still logged in
alice ttys000 Thu Mar 22 16:40 - 16:40 (00:00)