
There are different users in Linux. Some of them are default and some of them are created later. So, how can we list all these Linux users? What are the commands used to list users in Linux? In this lesson, we will learn different ways of Linux user listing.
You can check also Linux file listing lesson. (Linux ls options)
Table of Contents
All users in Linux system are stored in /etc/passwd file. You can list users by opening this file with cat, less, tail commands.
cat /etc/passwd
less /etc/passwd
tail /etc/passwd
You can also use an option to list only some part of these file. For example, to list the last 10 users, you can use “tail -10 /etc/passwd” command.
If you would like to list only the names of the users recorded in /etc/passwd, you can use the below command:
“awk -F’:’ ‘{ print $1}’ /etc/passwd”
You can check Linux Cheat Sheet For Useful Common Linux Commands.
We can list Linux users with also “getent” command. If we use this command without any filter comman, then it will give all the user information like /etc/passwd.
You can use grep command to get only one user information.
To list only usernames with getent command, we can use the below command:
“getent passwd | cut -d: -f1”
We can use compgen command for linux user listing. For example, we can use -u option with compgen command and list the names of the users in the linux system.
compgen -u
We can count the users in our Linux system. To do this, we can use getent command or compgen command by adding wc -l options.
Firstly, let’s use getent command with wc -l option to list our user.
“getent passwd | wc -l”
Now, let’s use compgen -u command with wc -l option.
“compgen -u | wc -l”
Gokhan Kosem is a Network Engineer, Instructor and the Founder of IPCisco.com with 15+ years of experience in Cisco, Nokia, Huawei, Juniper, Linux, Service Provider Networks, Routing and Switching technologies.
He has worked on the backbone networks of major service providers and network vendors including Nortel, Alcatel-Lucent (Nokia) and has extensive hands-on experience with Cisco, Huawei, Juniper and Nokia networking technologies.
He has trained thousands of networking students worldwide through IPCisco.com, Udemy, books, labs, quizzes, and educational content across multiple social media platforms.
IPCisco.com | Best Route to Your Dreams
Leave a Reply