[英]Getting the User ID from the last line of the /etc/passwd file in Linux
I've been trying the following:我一直在尝试以下方法:
cut -d: -f3 | last -1 /etc/passwd
and和
last -1 | cut -d: -f3 /etc/passwd
These statements aren't working, I'm not sure how to join both of them to get the result I want.这些语句不起作用,我不确定如何加入它们以获得我想要的结果。 It just takes the current command that is in front of the /etc/passwd directory.
它只需要 /etc/passwd 目录前面的当前命令。
I'm fairly new to Linux and combining commands together.我对 Linux 相当陌生,并将命令组合在一起。
Thank you for the help in advance.提前感谢您的帮助。
Try:尝试:
cut -d: -f3 /etc/passwd | tail -1
Or:或者:
tail -1 /etc/passwd | cut -d: -f3
The command last
shows a listing of last logged in users.命令
last
显示上次登录用户的列表。 By contrast, tail
provides the end of a file and tail -1
provides just the last line.相比之下,
tail
提供文件的结尾,而tail -1
只提供最后一行。
Consider this command:考虑这个命令:
cut -d: -f3 | last -1 /etc/passwd
This runs cut -d: -f3
but since in file names are provided, cut
will wait for you to provide input on stdin.这运行
cut -d: -f3
但由于提供了文件名, cut
将等待您在 stdin 上提供输入。 This is not what you want.这不是你想要的。 By contrast, the command below provides the file
/etc/passwd
as input to cut
and then selects the last line of cut's output:相比之下,下面的命令提供文件
/etc/passwd
作为cut
输入,然后选择 cut 输出的最后一行:
cut -d: -f3 /etc/passwd | tail -1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.