getent - get entries from administrative database

Hi! If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

getent is Unix command which helps you query one of the following administrative databases in Unix: passwd, group, hosts, services, protocols, or networks.

Administrative databases in Unix

As you can probably see from their names, the administrative databases are here to help you gather the most vital information about your environment:

  • passwd - can be used to confirm usernames, userids, home directories and full names of your users
  • group - all the information about Unix groups known to your system
  • services - all the Unix services configured on your system
  • networks - networking information - what networks your system belongs to
  • protocols - everything your system knows about network protocols

How to use getent

My home PC has a hostname of ubuntu. If I ever need to double-check which IPs this hostname points to, here's how I can use getent:

ubuntu$ getent hosts ubuntu
127.0.1.1       ubuntu
192.168.0.2     ubuntu

Using getent to find a UID by username

getent accepts various keys when searching in databases. For the passwd one, you can user either username or user id (UID) to search the database.

ubuntu$ getent passwd greys
greys:x:1000:1000:Gleb Reys,,,:/home/greys:/bin/bas

Using getent to find a username by UID

Like I said, the opposite will work as well:

ubuntu$ getent passwd 1000
greys:x:1000:1000:Gleb Reys,,,:/home/greys:/bin/bash

See also:

  • id - print user identity
  • who - see who is logged into the system
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Fark
  • Furl
  • Netscape
  • Reddit
  • Smarking
  • Spurl
  • StumbleUpon
  • Technorati
  • YahooMyWeb

1 comment so far ↓

#1 username by uid in Unix | UNIX Tutorial: Learn UNIX on 05.29.08 at 12:38 pm

[...] use the getent command. Most common use for it is to query the passwd source for a username, like [...]

Leave a Comment