Abhi
Abhi

Reputation: 6255

full unix username of a user

Wondering if you know if there is a slick way to get full username from shell?

example: if my unix username is froyo then I want to get my full name as registered in the system in this case [froyo  === Abhishek Pratap]

finger command does it but for all the logged in users at the same time ..so that needs some parsing to get the right value. Anything slicker ?

Anything from inside python would be great too.

Thanks! -Abhi

Upvotes: 6

Views: 3287

Answers (1)

isedev
isedev

Reputation: 19631

One way to achieve this is using pwd.getpwuid and os.getuid:

>>> import os
>>> import pwd
>>> pwd.getpwuid(os.getuid())[4]

This is the traditional Unix way of doing it (based on standard C library calls).

Upvotes: 15

Related Questions