Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In the /etc/passwd file on my system, the "comment" field, field 5, is inconsistent in its contents. I thought that I could extract it to get the full name of the user.

fullname=`awk -F: '$1 == name {print $5}' name=$LOGNAME /etc/passwd`

However this returns with $fullname containing a name with 0, 3, or 4 commas following. Exploring the man page (man 5 passwd) provides no details of this field other than describing it as "user name or comment field."

Perhaps there is additional information that is stored along with the user name?

share|improve this question
    
It is simply a comment field - e.g. this is an example: dbus:x:81:81:System message bus:/:/bin/false. I think the comments associated to a user account when created with useradd or adduser is put here. But I mean, who does that? –  Herman Torjussen Jan 7 '12 at 22:02
    
Then it must be my distro which has decided that commas belong there. –  TheGeeko61 Jan 7 '12 at 22:07
    
I have them too. It probably signifies that no comment is associated with the user. –  Herman Torjussen Jan 7 '12 at 22:09
add comment

1 Answer

up vote 4 down vote accepted

This field is often formatted as a GECOS field, which typically has 4 comma-separated fields for extra information in addition to the user's name, such as phone number, building number, etc.

In all cases I have seen, if the field has a comma, the name is what is before the comma. But I can imagine cases where this is not the case (a name of "Foo Bar, Jr" would break, for instance).

share|improve this answer
    
Excellent resource! Thank you! It's always a good feeling when one emerges from the darkness of ignorance. Your answer has helped me do this. :) –  TheGeeko61 Jan 7 '12 at 22:16
    
According to the man page for chfn, "The only restriction placed on the contents of the fields is that no control characters may be present, nor any of comma, colon, or equal sign." –  TheGeeko61 Jan 8 '12 at 1:25
    
Interestingly, the University of Cincinnati's browsable man pages is where I discovered that; but I don't see the same caveat in other man page sources... ?? –  TheGeeko61 Jan 8 '12 at 1:29
add comment

Your Answer

 
discard

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.