linux - 如何使用 bash 获取有关 ubuntu 中特定用户的所有信息?

标签 linux bash

现在我有这段代码,它只给我名称,但我想从文件/etc/passwd 中获取名称和其他信息,

#!/bin/bash

user=$1; 
grep home /etc/passwd | grep $user | cut -d: -f1;

我想得到完整的行,而不仅仅是我的名字。

最佳答案

这是当前用户的所有信息。请注意,由于 $USER 只是一个变量,因此可以更改它,而 id 命令提供实际用户。

myuser@PC:~$ getent passwd $(id -u)
myuser:x:1000:1000:"",,,:/home/myuser:/bin/bash
myuser@PC:~$ export USER=root
myuser@PC:~$ getent passwd $USER
root:x:0:0:root:/root:/bin/bash

关于linux - 如何使用 bash 获取有关 ubuntu 中特定用户的所有信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44874611/

相关文章:

linux - linux 上的 nsight 不适用于 cuda-gdb

linux - 从 Docker 运行 Spring Boot 应用程序不起作用

linux - 关于 pthread_barrier_wait

regex - BASH - 使用正则表达式查找和过滤查找特定文件夹

git - 无法安装 docker

c++ - 将 C++ Win32 应用程序移植到 linux 应用程序

linux - 如何在 linux 中读取开始日期和结束日期之间的所有日期

linux - bash 脚本 linux - 处理 ifconfig -a 输出的输出

linux - 为包含单引号的命令创建别名

linux - AWK 输出到数组