Friday, July 31, 2020

How to List the Users in Linux

List Out the Users in Linux

There may be the situations where you wanted to list out all the users available in Linux. In order to get the user details we have to use few commands as below.

The local user information is placed under /etc/passwd file. Each records in this file is actually a login information. So we will need to read this file. We can use cat to view the users as below.

$ cat   /etc/passwd

If the number of records are more then you can use less as below:

less /etc/passwd

Command:



The Output of this command will be as below:

Output:



Now, If you want to display only username then you can use cut command to print only the first column which holds the username as below:

$ cut -d: -f1 /etc/passwd


Output:


There is one another command to display the list of user in linux i.e. getend.This command displays the entries from databases configured in /etc/nsswitch.conf file

You can use this command as below to list the users

$ getent passwd

And to list only the user name you can use this command as below

$ getent passwd | cut -d: -f1


Command:
$ getent passwd | cut -d: -f1


Output:



Thank You!
Vimal