Score:0

You can modify user data with chfn (e.g. phone, room) but how can you just display that organisational data?

am flag

Edit: @steeldriver provided the answer I believe. I think I found the reason why I did not get the output that I wanted in the first place. When I created the user I entered Full Name, Room Number, Work Phone, Home Phone and Other. But I overlooked an error message. Even though the organisational information (aka GECOS information as @muru made me aware of) is missing the user was created successfully it seems. The error message read:

chfn: fields too long
adduser: `/bin/chfn user_that_i_created' returned error code 1. Exiting.

End of edit.

Sorry for asking this, I really tried to find the answer myself and I seem to be unable to ask Google the right question to find the answer I need.

Ok, so we all know how to find user data which is interesting from a technical point of view, using /etc/passwd and grep or other commands. But this is not what I am looking for.

When you create a user, you are asked for room, work phone and other organisational data. You would change that data with chfn. But how can you just output that data? It must be in some file I guess? Can I do cat [file where organisational user data is stored] to see the phone number, room number, etc? How can I display that information?

muru avatar
us flag
Are you talking about GECOS information? That's stored in `/etc/passwd`.
Score:2
hr flag

The fn in chfn stands for fullname, and the information is stored in the fullname field of the password database - or what man 5 passwd calls the

·   user name or comment field

(it's also commonly referred to as the GECOS field). So you can retrieve it using getent

$ getent passwd testuser
testuser:x:1001:1001:John Doe,101,234-555-1224,689-555-3785:/home/testuser:/bin/sh

If you're using local account management (rather than some kind of distributed management such as NIS or LDAP), the data is stored as plain text in the /etc/passwd file, and may be accessed directly with cat or less or with any of the various text processing tools ex.

$ awk -F: -v user=testuser '$1 == user {print $5}' /etc/passwd
John Doe,101,234-555-1224,689-555-3785

You can also use the finger command to access it in human readable format:

$ finger -l testuser
Login: testuser                         Name: John Doe
Directory: /home/testuser               Shell: /bin/sh
Office: 101, 234-555-1224               Home Phone: 689-555-3785
Last login Thu Jul  8 14:41 (EDT) on pts/2 from 192.168.1.4
No mail.
No Plan.
Terrance avatar
id flag
WOW! I was just going to write about the `getent` command. Nice answer! +1 However, finger is not installed by default. :( But I definitely like the output of `finger` a lot more than `getent`. :)
hr flag
@Terrance maybe the awked version is cleaner? that could be applied to the `getent` version as well of course
Terrance avatar
id flag
Yeah, the `awk` version is a lot cleaner. You have given me some really good ideas on what to do with my team info here in my own office (well, really I work from home still but I have been looking for more ways to store tech info and locations). You have helped me TONS even though I am not the OP of the question. :)
raj avatar
cn flag
raj
In the old times of the Internet ;), `finger` was commonly used to obtain information about remote users, you could just type `finger [email protected]` to get the info about user of almost any server. As far as I know, the GECOS field was meant specifically to be used with `finger` command.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.