Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to get a user's real life name based to print during the login script.

I'm using currently the following command:
finger | grep $LOGNAME | head -1 | awk '{print $2 " " $3}'

Is there any better way? I did not see in finger's man page that it has an argument to get only the real life name.

I'm using TCSH on a SunOs machine.

share|improve this question
up vote 1 down vote accepted

getent passwd $LOGNAME | awk -F ":" '{print $5}' should be easier. The real name is called 'gecos'

share|improve this answer
Eventually I took the getent passwd from your answer combined with MadHAtter's cut -f5 -d: | cut -f1 -d,. I prefer cut over awk – RonK May 11 '11 at 9:20
you presents awk in your example, it is why I use it. Choose the faster ! – Dom May 12 '11 at 14:30

That's just the GECOS field from the password file, so you could get it directly from there if you wanted to:

grep -w $LOGNAME /etc/passwd|cut -f5 -d:

If someone were using the GECOS field to store more than the full name, eg an office telephone number as well (as is permitted, but is no longer common), you'd need to run it through another cut to get only the "full name" portion of the field:

grep -w $LOGNAME /etc/passwd|cut -f5 -d:|cut -f1 -d,
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.