getent 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

getent 命令安装:


  1. -bash: getent: command not found
  2.  
  3. #Debian
  4. apt-get install libc-bin
  5.  
  6. #Ubuntu
  7. apt-get install libc-bin
  8.  
  9. #Arch Linux
  10. pacman -S glibc
  11.  
  12. #Kali Linux
  13. apt-get install libc-bin
  14.  
  15. #CentOS
  16. yum install glibc-common
  17.  
  18. #Fedora
  19. dnf install glibc-common
  20.  
  21. #Raspbian
  22. apt-get install libc-bin

getent 命令补充说明:


getent 从数据库命令显示的条目由 Name 服务切换库,其被配置成在支持 /etc/nsswitch.conf 中。如果提供一个或多个键自变量,则仅显示与提供的键匹配的条目。否则,如果未提供键,则将显示所有条目(除非数据库不支持枚举)。

getent 命令语法:


  1. getent database [key ...]

getent 命令选项:


  1. Get entries from administrative database.
  2.  
  3. -s, --service=CONFIG 要使用的服务配置
  4. -?, --help 给出该系统求助列表
  5. --usage 给出简要的用法信息
  6. -V, --version 打印程序版本号

getent 命令支持的数据库:


  1. ahosts ahostsv4 ahostsv6 aliases ethers group gshadow hosts netgroup
  2. networks passwd protocols rpc services shadow

getent 命令实例:


getent 获取所有组的列表:

  1. getent group
  2.  
  3. root:x:0:
  4. bin:x:1:
  5. daemon:x:2:
  6. sys:x:3:
  7. adm:x:4:
  8. tty:x:5:
  9. disk:x:6:
  10. lp:x:7:
  11. mem:x:8:
  12. kmem:x:9:
  13. wheel:x:10:
  14. cdrom:x:11:
  15. mail:x:12:postfix
  16. man:x:15:
  17. dialout:x:18:
  18. floppy:x:19:
  19. games:x:20:
  20. tape:x:30:
  21. video:x:39:
  22. ftp:x:50:
  23. lock:x:54:
  24. audio:x:63:
  25. nobody:x:99:
  26. users:x:100:
  27. utmp:x:22:
  28. utempter:x:35:
  29. ssh_keys:x:999:
  30. input:x:998:
  31. systemd-journal:x:190:
  32. systemd-network:x:192:
  33. dbus:x:81:
  34. polkitd:x:997:
  35. postdrop:x:90:
  36. postfix:x:89:
  37. chrony:x:996:
  38. sshd:x:74:
  39. ntp:x:38:
  40. tcpdump:x:72:
  41. nscd:x:28:
  42. screen:x:84:
  43. mysql:x:1001:
  44. apache:x:48:
  45. slocate:x:21:
  46. tss:x:59:
  47. rvm:x:1003:
  48. www:x:1002:
  49. jumpserver:x:1004:
  50. wentao:x:1005:
  51. luojunxue:x:1006:
  52. clamupdate:x:995:
  53. virusgroup:x:994:clamupdate,clamilt,clamscan
  54. clamilt:x:993:
  55. clamscan:x:992:
  56. prodev01:x:1007:

getent 查看群组成员:

  1. getent group group_name

getent 获取所有服务的列表:

  1. getent services
  2.  
  3. #比如:
  4. $ getent services 80
  5. http 80/tcp www www-http

getent 根据当前登录信息查找 UID

  1. $ getent passwd `whoami`
  2. www:x:1002:1002::/home/www:/bin/bash

getent 通过 UID 查找用户名:

  1. getent passwd 1000

getent 执行反向 DNS 查找:

  1. getent hosts host
  2.  
  3. #比如:
  4. $ getent hosts www.hexun.com
  5. 119.97.159.10 wsctcwhngtxdl01.fastcdn.hexun.com www.hexun.com www.fastcdn.hexun.com
  6.  
  7. $ getent hosts command-not-found
  8. 192.168.1.23 command-not-found

getent 命令扩展阅读:




getent 命令评论

共收录到 524Linux 命令