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
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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.