在Unix中如何获取登录用户的真实姓名? [英] How to get the logged in user's real name in Unix?

查看:23
本文介绍了在Unix中如何获取登录用户的真实姓名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望找出登录用户的真实姓名(全名),以避免在我正在构建的应用程序中提示他们输入.我看到 finger 命令将输出包含此内容的列数据列表,并想知道通过此 grep 是否有意义还是有更简单的方法?我发现的手指开关都没有输出真实姓名.任何想法将不胜感激.

I'm looking to find out the logged in user's real (full name) to avoid having to prompt them for it in an app I'm building. I see the finger command will output a columned list of data that includes this and was wondering if it makes sense to grep through this or is there an easier way? None of the switches for finger that I've found output just the real name. Any thoughts would be much appreciated.

推荐答案

getent passwd `whoami` | cut -d : -f 5

(getent 通常比 grepping /etc/passwd 更可取).

(getent is usually preferable to grepping /etc/passwd).

这篇关于在Unix中如何获取登录用户的真实姓名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆