A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/linux-unix/getent-command-in-linux-with-examples/ below:

getent command in Linux with examples

getent command in Linux with examples

Last Updated : 03 Sep, 2024

The 'getent' command in Linux is a powerful tool that allows users to access entries from various important text files or databases managed by the Name Service Switch (NSS) library. This command is widely used for retrieving user and group information, among other data, stored in databases such as 'passwd', 'group', 'hosts', and more. 'getent' provides a consistent and unified way to query the local files like '/etc/passwd' or network information sources such as LDAP.

What is the 'getent' Command?

The 'getent' (short for "get entries") command fetches entries from specified databases supported by NSS. This makes it a versatile tool for looking up a wide range of information on a Linux system, including user accounts, groups, hosts, services, and more. Since it uses the same name service as the system, 'getent' can retrieve data from both local files and network sources like LDAP, providing a complete view of the requested information.

Common Databases Queried by 'getent'

The 'getent' command can query several databases, each serving a different purpose. Some of the most commonly accessed databases include:

Other databases 'getent' can query include 'ahosts', 'ahostsv4', 'ahostsv6' (for address resolution), 'ethers' (Ethernet addresses), 'gshadow' (secure group information), 'netgroup', 'rpc' (remote procedure call), and more.

'getent' Command Examples in Linux

Here are some practical examples:

Example 1: Fetching All User Accounts

Fetch the list of user accounts on a Linux system (stored in a database known as 'passwd'). This will show all the user accounts, regardless of the type of name service being used. For example, if both the local and the LDAP name service are used for user accounts, the results will include all the local and the LDAP users:

Syntax:

getent database [key ...]

Output:

Explanation: This command displays all user accounts, including those from both local and network sources like LDAP.

Example 2: Fetching Specific User Information

If we want to fetch details for a particular user called 'rahul' then,

Syntax:

getent passwd rahul

Output:

Explanation: This outputs the user details from the 'passwd' database, including the username, user ID, group ID, home directory, and default shell.

Example 3: Fetching Group Information

If we want to fetch a list of group accounts on a Unix system (stored in a database called 'group') then,

Syntax:

getent group

Output:

Explanation: This shows details of each group, including group name, group ID, and group members.

Options for 'getent'

While 'getent' is simple in its basic usage, it also offers options to modify its behavior:

Exit Status Codes

One of the following exit values can be used to returned by getent:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4