Linux Commands Ubuntu

List Users with awk Command in Ubuntu

List Users with awk Command in Ubuntu

For administrators, in Ubuntu, listing users is a crucial task for User Management as It helps in improving security by checking for unauthorized users. User Management can also be used to troubleshoot problems in Ubuntu. The “awk” command is a useful way to display Users in Ubuntu by listing them in the Terminal. The “awk” Command is used as a search pattern. It is used to find patterns in a file or filter a text file according to specified criteria.

This article explains the different methodologies in which the “awk” command can be used to list users in Ubuntu.

List Users With the “awk” Command in Ubuntu

As the “awk” command is used to filter search, it can be used with the “getent passwd” command. The “getent passwd” is used to retrieve all users. The “awk” can be used with it to filter based on a query.

To list the details of users, the “getent passwd” command can be used:

sudo getent passwd

This will list all the users and their complete details including the UID as well:

To display only the names of the users, the “awk” command is used with the “getent passwd” command:

getent passwd | awk -F: '{print $1}'

This will display all the user names only in the terminal:

List User UID with the “awk” Command in Ubuntu

The “getent passwd” Command returns the list of users and additional details of the users as well. The UID of the users is also included and can be returned or listed using the “-F print{}” command with awk specifying to return only the specific column. To return only the User ID, the third column of the list is included in the “awk” command:

getent passwd | awk -F: '{print $3}'

The “print $3” command ensures to display the third column of the Users List, i.e. the UIDs of users:

List Filtered User UID With “awk” Command in Ubuntu

Conditions can also be passed to filter users. To display the users having a UID less than 100, the command used is:

getent passwd | awk -F: '{if($3<100) print $1}'

The “($3<100)” ensures to return the users having UID less than 100:


The “awk” command is useful to filter the search. It is used with the “getend passwd” to return users of the specific types according to your specific needs. This article explained different ways in which you can use the “awk” command to list users.


Similar Posts