FUNDAMENTALS A Complete Guide for Beginners
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...
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.
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.
Similar Readings
- The “apt-get” Command in Linux [10 Practical Examples]
- The “firewall-cmd” Command in Linux [7 Practical Examples]
- The “finger” Command in Linux [6 Practical Examples]
- The “env ” Command in Linux [9 Practical Examples]
- The “enable” Command in Linux [6 Practical Examples]
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.
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.
Similar Readings
- The “time” Command in Linux [4 Practical Examples]
- The “tty” Command in Linux [4 Practical Examples]
- The “uptime” Command in Linux [5 Practical Examples]
- The “vmstat” Command in Linux [6 Practical Examples]
- The “uname” Command in Linux [11 Practical Examples]
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.
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.
Similar Readings
- The “free” Command in Linux [8 Practical Examples]
- The “df” Command in Linux [11 Practical Examples]
- The “groupadd” Command in Linux [7 Practical Examples]
- The “addgroup” Command in Linux [7 Practical Examples]
- The “groups” Command in Linux [6 Practical Examples]
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.
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.
Similar Readings
- The “groupmod” Command in Linux [5+ Practical Examples]
- The “id” Command in Linux [7+ Practical Examples]
- The “service” Command in Linux [6 Practical Examples]
- The “sestatus” Command in Linux [4 Practical Examples]
- The “shutdown” Command in Linux [7 Practical Examples]
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.
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.
Similar Readings
- The “dmesg” Command in Linux [7+ Practical Examples]
- The “install” Command in Linux [6+ Practical Examples]
- The “reboot” Command in Linux [3 Practical Examples]
- The “sync” Command in Linux [8 Practical Examples]
- The “chage” Command in Linux [7 Practical Examples]
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.
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.
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