Linux last コマンド

Linux 命令大全Linux コマンド大全

Linux last コマンドは、ユーザーの最近のログイン情報を表示するために使用します。

単独で実行するlastコマンドは、/var/log ディレクトリにある wtmp という名前のファイルを読み取り、そのファイルに記録されたログインユーザー名をすべて表示します。

構文

last [options] [username...] [tty...]

パラメータの説明:

options:

  • -R ホスト名 (hostname) の列を省略します。
  • -a ログイン元のホスト名またはIPアドレスを最後の行に表示します。
  • -d IPアドレスをホスト名に変換します。
  • -f<記録ファイル> 記録ファイルを指定します。
  • -n<表示行数> または -<表示行数> 表示する行数を指定します。
  • -R ログイン元のホスト名またはIPアドレスを表示しません。
  • -x システムのシャットダウン、再起動、ランレベルの変更などの情報を表示します。

username:

  • username: 指定したユーザー username のログイン情報を表示します。

tty:

  • tty ログインする端末を設定します。tty の名前は省略でき、last 0とlast tty0同じです。

例

2行を表示し、ホスト名 (hostname) の列を省略します:

# last -R -2
root     pts/0        Thu Apr 28 18:06   still logged in
root     pts/0        Tue Apr 26 09:06 - 19:36  (10:30)

wtmp begins Sun Apr  3 13:11:25 2022

2行を表示し、ホストの列を省略します:

~# last -R -2
root     pts/0        Thu Apr 28 18:06   still logged in
root     pts/0        Tue Apr 26 09:06 - 19:36  (10:30)

wtmp begins Sun Apr  3 13:11:25 2022

一般的な表示方法:

# last
...
root   pts/4    Thu May 13 17:25  still logged in  
root   pts/2    Thu May 13 17:23 - 17:25 (00:02)  
root   pts/1    Thu May 13 16:46  still logged in  
...

簡略表示し、表示する個数を指定します:

# last -n 5 -R
root   pts/4    Thu May 13 17:25  still logged in  
root   pts/2    Thu May 13 17:23 - 17:25 (00:02)  
root   pts/1    Thu May 13 16:46  still logged in  
root   pts/7    Thu May 13 15:36  still logged in  
root   pts/9    Thu May 13 15:35  still logged in  

wtmp begins Thu May 13 18:55:40 2014

最後の列にホストのIPアドレスを表示します:

# last -n 5 -a -i
root   pts/4    Thu May 13 17:25  still logged in  192.168.1.10
root   pts/2    Thu May 13 17:23 - 17:25 (00:02)   192.168.1.10
root   pts/1    Thu May 13 16:46  still logged in  192.168.1.10
root   pts/7    Thu May 13 15:36  still logged in  192.168.1.10
root   pts/9    Thu May 13 15:35  still logged in  192.168.1.10

wtmp begins Thu May 13 18:55:40 2014

Linux 命令大全Linux コマンド大全

その他の拡張