DrB*_*eco 6 linux bash shell-script c finger
在文件中/etc/passwd
我们有所谓的GECOS fields
(代表“通用电气综合操作系统”),即:
username:password:userid:groupid:gecos:home-dir:shell
Run Code Online (Sandbox Code Playgroud)
其中GECOS
分为:
:FullName,RoomAddress,WorkPhone,HomePhone,Others:
Run Code Online (Sandbox Code Playgroud)
并被Others
分成任意多的逗号:
:FullName,RoomAddress,WorkPhone,HomePhone,Other1,Other2,Other3:
Run Code Online (Sandbox Code Playgroud)
在man chfn
页面中可以阅读:
另一个字段用于存储其他应用程序使用的记帐信息。
现在,应用程序开发人员(我很感兴趣C language
,system calls
和/或bash script
),这就是抓住这个信息的最佳方式?
仅考虑Bash
环境,鉴于该finger
命令无法显示others
字段(或者至少我不知道如何显示),还有哪些其他命令可以显示?我知道这chfn
不仅是展示,而且是允许它们被改变。如果只是将它输出到stdout
怎么办?
小智 4
我发现的最好方法是使用,getent
因为这将与 LDAP/NIS 或非本地用户的其他方法一起使用
getent passwd $UID| awk -F ":" '{print $5}'
Run Code Online (Sandbox Code Playgroud)