The “getent” Command in Linux [11 Practical Examples]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

There are many command-line tools in Linux that can be used to access user information stored in a database. One such tool is called “getent,” which stands for “get entries from the administrative database.” In this article, I will describe all the features and uses of the getent command in Linux with multiple examples.

A. Description

The getent command in Linux is a tool that enables the retrieval of data from system databases such as passwd, group, and services. It can be utilized to either list all entries in a database or obtain information about a specific entry.

B. Syntax

The syntax of the getent command in Linux is pretty simple, as shown below.

getent [OPTION]... database key...
Note: In the syntax above, the OPTION enclosed by the square bracket means it is not mandatory and three dots after the square bracket mean multiple OPTIONS can be used after the getent command. Again, if specific keys are given as arguments, only the entries corresponding to those keys will be shown. If no keys are provided, all entries will be displayed

C. Options

There are numerous options available for the getent command. I have listed a few of them. You can learn more about the getent command, its options and their uses by checking the man page.

man getent

Useful Options

  • -s,–service: Used to specify the service.
  • -i,–no-idn: Used to disable IDN encoding in lookups.
  • -?, –help: Show user help page.
  • –usage: Display usage information.
  • -V, –version: Display the version number, license, and disclaimer for getent.
Note: Commands and their options are case-sensitive in Linux. So, be careful while using them.

Practical Examples of the “getent” Command in Linux

The getent command in Linux retrieves entries from various databases, such as passwd, group, and shadow, by specifying the database and a key. In the section below, I will show you some of the most useful applications for the getent command in Linux.

Example 1: List All the User Accounts on a Linux System

The getent command in Linux allows you to see the list of all users by using the passwd argument with the command. You can retrieve information about the users in your system, including their usernames, user IDs, and home directories. Here, I will display a list of all users in my system on the terminal with the getent command. You can do the same by following the steps below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command into the command prompt:

getent passwd

➌ Now, press the ENTER button.

Output >

In the following image, you can see that I have displayed the list of all users in my system using the getent command.Showing the list of all users in my system using the getent command in Linux.


Similar Readings


Example 2: Fetch Details for a Particular User

You can see the details of a specific user on your Linux machine using the getent command followed by the argument  passwd and then the user_name. You will get information about the user, including his username, user ID, and home directory. Here, I will display the information of a specific user named “jack” in my system on the terminal with the getent command. You can do the same by following the steps below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command into the command prompt:

getent passwd jack

➌ Now, press the ENTER button.

Output >

In the following image, you can see that I have displayed the information about user jack in the terminal using the getent command.Showing the information about user "jack" in the terminal using the getent command in Linux.

Example 3: List All the Groups on a Linux System

The getent command in Linux allows you to see the list of all groups by using the group argument with the command. You can retrieve information about the groups in your system, including their names, GIDs, and some additional information. Here, I will display a list of all groups in my system on the terminal with the getent command. You can do the same by following the steps below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command into the command prompt:

getent group

➌ Now, press the ENTER button.

Output >

In the following image, you can see that I have displayed the list of all groups in my system using the getent command.Showing the list of all groups in my system using the getent command in Linux.


Similar Readings


Example 4: Fetch Details of a Particular Group With the “getent” Command in Linux

You can see the details of a specific group on your Linux machine using the getent command followed by the argument group and then the group_name. You will get information about the group, including his group name, GID and some additional information like member names(if stored in the database). Here, I will display the information of a specific group named lpadmin in my system on the terminal with the getent command. You can do the same by following the steps below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command into the command prompt:

getent group lpadmin

➌ Now, press the ENTER button.

Output >

In the following image, you can see that I have displayed the information about the group named lpadmin in the terminal using the getent command.Showing the information about the group named "lpadmin" in the terminal using the getent command in Linux.

Example 5: List All the Services on a Linux System

The getent command in Linux allows you to see the list of all services by using the services argument with the command. You can retrieve information about the services in your system, their associated port numbers and protocol types. Here, I will display a list of all services in my system on the terminal with the getent command. You can do the same by following the steps below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command into the command prompt:

getent services

➌ Now, press the ENTER button.

Output >

In the following image, you can see that I have displayed the list of all services in my system using the getent command.Showing the list of all services in my system using the getent command in Linux.


Similar Readings


Example 6: Fetch Details for a Particular Service With the “getent” Command in Linux

You can see the details of a specific service on your Linux machine using the getent command, followed by the argument services and then the service_name. You will get information about the service, its associated port number and protocol type. Here, I will display the information of a specific service named kpasswd (this service is used while changing the user password) in my system on the terminal with the getent command. You can do the same by following the steps below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command into the command prompt:

getent services kpasswd

➌ Now, press the ENTER button.

Output >

In the following image, you can see that I have displayed the information about the service named kpasswd in the terminal using the getent command.Showing the information about the service named kpasswd in the terminal using the getent command in Linux.

Example 7: List All Hostnames and Their IP Addresses on a Linux System

You can see the list of all services by using the hosts argument with the getent command in Linux. You can retrieve information about the hosts in your system along with their IP addresses. Here, I will display a list of all hosts in my system on the terminal with the getent command. You can do the same by following the steps below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command into the command prompt:

getent hosts

➌ Now, press the ENTER button.

Output >

In the following image, you can see that I have displayed the list of all hosts in my system using the getent command.Showing the list of all hosts in my system using the getent command.

Showing file system excluding a file system type


Similar Readings


Example 8: List All Networks and IP addresses on a Linux System

The getent command in Linux allows you to see the list of all networks by using the networks argument with the command. You can retrieve information about the networks in your system along with their addresses. Here, I will display a list of all networks in my system on the terminal with the getent command. You can do the same by following the steps below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command into the command prompt:

getent networks

➌ Now, press the ENTER button.

Output >

In the following image, you can see that I have displayed the list of all networks in my system using the getent command.Showing the list of all networks in my system using the getent command.

Example 9: Get the Short Usage Summary of the “getent” Command in Linux

To view a list of the available options for using the getent command in Linux, you can simply add the –usage option after the command. Here, I will display a short list of all usages of the getent command. You can do the same by following the steps below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command into the command prompt:

getent --usage

➌ Now, press the ENTER button.

Output >

In the following image, you can see that I have displayed the short list of all usages of the getent command.Showing the short list of all usages of the getent command.


Similar Readings


Example 10: Get the Version of the “getent” Command in Linux

You can see the current version of the getent command in your Linux machine. Here, I will show you the version of the getent command of my machine on the terminal. You can do the same by following the steps below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command into the command prompt:

getent --version

➌ Now, press the ENTER button.

Output >

In the following image, you can see that I have displayed the version of the getent command in Linux.displaying the version of the getent command in Linux.

Example 11: Get Help About the “getent” Command in Linux

In Linux, the help page for the getent command contains a brief description of the command. You can see the help page by following the steps that I mentioned below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command into the command prompt:

getent --help

➌ Now, press the ENTER button.

Output >

In the following image, you can see the help page of the getent command in Linux.Showing the help page of the getent command in Linux.

Conclusion

In this article, I’ve illustrated a few of the useful operations of the getent command. I’ve also provided some relevant examples. You should be able to use the getent command effectively on your own if you properly read this article and follow the above-mentioned guidelines. I hope these examples will help you on your journey to be a power user of the Linux command line.


Similar Readings

Rate this post
S. M. Amdadul Islam

Hello everyone. I am S. M. Amdadul Islam, currently working as a Linux Content Developer Executive at SOFTEKO. I am a Naval Architecture and Marine Engineering (NAME) graduate from the Bangladesh University of Engineering and Technology. In addition to my regular work, I enjoy watching Youtube, discovering new things, gossiping with friends, visiting new places, and taking photos of landscapes. Read Full Bio

Leave a Comment