![](/img/trans.png)
[英]How to print no.of users logged into the linux server along with shell from /etc/passwd file in linux
[英]Getting the User ID from the last line of the /etc/passwd file in Linux
我一直在嘗試以下方法:
cut -d: -f3 | last -1 /etc/passwd
和
last -1 | cut -d: -f3 /etc/passwd
這些語句不起作用,我不確定如何加入它們以獲得我想要的結果。 它只需要 /etc/passwd 目錄前面的當前命令。
我對 Linux 相當陌生,並將命令組合在一起。
提前感謝您的幫助。
嘗試:
cut -d: -f3 /etc/passwd | tail -1
或者:
tail -1 /etc/passwd | cut -d: -f3
命令last
顯示上次登錄用戶的列表。 相比之下, tail
提供文件的結尾,而tail -1
只提供最后一行。
考慮這個命令:
cut -d: -f3 | last -1 /etc/passwd
這運行cut -d: -f3
但由於提供了文件名, cut
將等待您在 stdin 上提供輸入。 這不是你想要的。 相比之下,下面的命令提供文件/etc/passwd
作為cut
輸入,然后選擇 cut 輸出的最后一行:
cut -d: -f3 /etc/passwd | tail -1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.