e Learning

How to list Users in Ubuntu Linux

In this tutorial we are going to learn how to list users in Ubuntu Linux.

Ubuntu Linux does not have a single Linux command to get the list of users on the system. But we can get the userlist by outputting the content of the /etc/passwd file, since /etc/passwd file contains information about all users.

We also need to combine cat command with the awk to list usernames only.

cat /etc/passwd | awk -F: ‘{print $1}’

list users ubuntu cat command

Create Command Alias to List All users in Ubuntu

To make things easy, we can create a command alias which will point to the above command we used. To create the Alias first we need to create the alias file in the /etc/profile.d directory.

vim /etc/profile.d/listusers.sh

Then Add the following line to create a command alias called listusers.

alias listusers=”cat /etc/passwd | awk -F: ‘{print \$1}'”

After you add the command alias, re login to the Linux shell and type


ubuntu list all users command alias

User names of the all users in your Ubuntu system will get printed. This method can also use to list groups using /etc/group file.

What we learned?