簡體   English   中英

在 Linux 中從 /etc/passwd 文件的最后一行獲取用戶 ID

[英]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

筆記

  1. 命令last顯示上次登錄用戶的列表。 相比之下, tail提供文件的結尾,而tail -1只提供最后一行。

  2. 考慮這個命令:

     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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM