• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

getent Command Examples in Linux

by Deepika

getent is a command line utility that allows you to access the entries stored in various Name Service Switch (NSS) libraries on a Linux or Unix-like system. NSS is a library that provides a unified interface to various system databases, such as /etc/passwd and /etc/group, as well as network information services like LDAP and NIS.

getent can be used to query various types of database, including passwd, group, hosts, services, protocols, and networks. You can use it to look up information about specific users, groups, or host names, for example. The syntax for using getent is as follows:

# getent [database] [key]

where database is the name of the database you want to query (e.g. passwd, group, hosts) and key is the name or identifier of the entry you’re looking for (e.g. a username or hostname).

For example, to look up information about a specific user, you would use the following command:

# getent passwd [username]

This will return the entire line of information associated with the specified user from the /etc/passwd file. Similarly, you can use:

# getent group [groupname]

to get information about a specific group from the /etc/group file.

You can also use getent without any arguments to display all the entries in a given database.

# getent passwd

This command will display all the entries in the /etc/passwd file.

getent Command Examples

1. Get list of all groups:

# getent group

2. See the members of a group:

# getent group group_name

3. Get list of all services:

# getent services

4. Find a username by UID:

# getent passwd 1000

5. Perform a reverse DNS lookup:

# getent hosts host

Filed Under: Linux

Some more articles you might also be interested in …

  1. pivpn Command Examples in Linux
  2. gs Command Examples in Linux
  3. useradd Command Examples in Linux
  4. How systemd-tmpfiles cleans up /tmp/ or /var/tmp (replacement of tmpwatch) in CentOS / RHEL 7
  5. “device-mapper: resume ioctl failed: Invalid argument” – error on running lvcreate/lvresize/lvextend
  6. How to Switch Module Streams in CentOS/RHEL 8
  7. How to Enable Password Aging in Linux with NIS
  8. whereis: command not found
  9. aspell: command not found
  10. jpegtran for image optimization

You May Also Like

Primary Sidebar

Recent Posts

  • “aws s3 mv” Command Examples
  • “aws s3 mb” Command Examples
  • “aws s3 ls” Command Examples
  • “aws s3 cp” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright