getent 查找特定信息
getent命令帮助用户administrative databases中查找相关信息。administrative databases包括:
- 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
一般语法
etent database [key ...]
getent会在上面数据库中产找key对应的value
举例
1、根据用户找uid
root@centos7 data]# getent passwd root
root:x:0:0:root:/root:/bin/bash
2、根据UID 查找用户
[root@centos7 data]# getent passwd 0
root:x:0:0:root:/root:/bin/bash
3、获取当前用户登录信息
[root@centos7 data]# getent passwd `whoami`
root:x:0:0:root:/root:/bin/bash
4、查询哪个服务在使用特定的端口号
[root@centos7 data]# getent services 80
http 80/tcp www www-http
5、根据用户查询秘密啊密文
root@centos7 data]# getent shadow root
root:$6$kV8SBiDui0Qs.08P$9tawQDNQrmjRgIg6rW7tJu35o9la7UPzXvP61SP7Ba1at5KrcaWgpKiJIovTKyb9V.2r/weuiMQYDXXFe1nIs1::0:99999:7:::