用户的完整 unix 用户名 [英] full unix username of a user

查看:63
本文介绍了用户的完整 unix 用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想知道是否有一种巧妙的方法可以从 shell 获取完整的用户名?

<块引用>

示例:如果我的 unix 用户名是 froyo 那么我想得到我的全名在这种情况下已在系统中注册 [froyo === Abhishek Pratap]

finger 命令可以做到这一点,但是对于所有登录的用户来说都同时......所以需要一些解析来获得正确的值.有什么更好的吗?

python 内部的任何东西都会很棒.

谢谢!-阿比

解决方案

实现此目的的一种方法是使用 pwd.getpwuidos.getuid:

<预><代码>>>>导入操作系统>>>输入密码>>>pwd.getpwuid(os.getuid())[4]

这是传统的 Unix 方式(基于标准的 C 库调用).

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).

这篇关于用户的完整 unix 用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆