简体   繁体   English

用户的完整unix用户名

[英]full unix username of a user

Wondering if you know if there is a slick way to get full username from shell? 想知道你是否知道有一种灵巧的方式从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] 例如:如果我的unix用户名是froyo,那么我想在我的系统中注册我的全名[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. finger命令可以同时为所有登录用户执行此操作..因此需要进行一些解析才能获得正确的值。 Anything slicker ? 有什么东西吗?

Anything from inside python would be great too. 来自python内部的任何东西都会很棒。

Thanks! 谢谢! -Abhi -Abhi

One way to achieve this is using pwd.getpwuid and os.getuid : 实现此目的的一种方法是使用pwd.getpwuidos.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). 这是传统的Unix方式(基于标准C库调用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM