last command

LINUX-Frequently used commands

last command View the history of logins to the system
Syntax
last   [Option]  [User-name]  [Terminal number]
Last” is a command that lists the system’s login history..
The file /var/log/wtmp is browsed, starting with the most recent login..
Frequently used options
-n <number of lines>, -<number of lines>      Specify the number of lines to display
-t <Date>       Display login information prior to the specified date and time (YYYYMMDDhhmmss)
-x     Also shows records of system shutdowns and run level changes
-R    Do not display the hostname field
-a    Display the host name in the last column
-d    When logging in remotely, the IP address of the login source is converted to a host name and displayed
-i      When logging in remotely, show the IP address of the login source
-f <File name>    Specify the file to be used instead of the “/var/log/wtmp” file
-o    Read old format wtmp files
Example: View your login history.
$  last
usr01     pts/1               192.168.56.1    Sat Jul 13 06:00      still logged in

usr01     pts/                 0 :0.0               Sat Jul 13 06:00   – 06:01 (00:00)
usr01     tty7                 :0                     Sat Jul 13 06:00      gone – no logout
reboot    system boot     3.0.77-1vl6       Fri Jul 12 20:58    –  06:22 (09:23)
root        pts/1              192.168.56.1     Sat Jul 6 21:45    –   down (00:00)
root        pts/1              192.168.56.1     Sat Jul 6 21:28    –   21:45 (00:17)
usr01      pts/0              :0.0                  Sat Jul 6 21:27     –   down (00:18)
usr01      tty7                :0                     Sat Jul 6 21:27     –   down (00:18)
reboot     system boot    3.0.77-1vl6        Sat Jul 6 21:26    –    21:45 (00:19)
usr01      pts/0               :0.0                  Sat Jul 6 21:24    –    down (00:01)
usr01      tty7                 :0                     Sat Jul 6 21:23    –    down (00:01).
Example: View history by user
$ last user1 ←The login history of “user1” is displayed.
user1 pts/4 192.168.11.100 Sat Jan 22 12:54 still logged in
user1 pts/3 Sat Jan 22 12:30 still logged in
user1 pts/4 192.168.11.100 Fri Jan 21 01:10 – down (00:41)
user1 pts/3 Fri Jan 21 01:09 – down (00:42)
user1 pts/3 192.168.11.100 Wed Jan 19 01:05 – down (00:00)
user1 pts/4 192.168.11.100 Wed Jan 19 00:19 – 01:05 (00:46)
user1 pts/3 Tue Jan 18 23:55 – 01:05 (01:10)
user1 pts/5 192.168.11.100 Fri Jan 14 01:06 – 01:21 (00:15)
user1 pts/4 192.168.11.100 Fri Jan 14 00:36 – down (00:45)
user1 pts/4 192.168.11.100 Wed Jan 12 23:55 – 00:47 (00:51)
user1 pts/4 192.168.11.100 Tue Jan 11 23:30 – 00:01 (00:30)
Example: Specify the number of lines to display
$ last -3 ←Run it with the option “-3”
user1 pts/5 192.168.11.100 Sat Jan 22 13:08 still logged in
user2 pts/4 192.168.11.100 Sat Jan 22 12:54 still logged in
user2 pts/3 Sat Jan 22 12:30 still logged in
Example: Replace multiple consecutive blank lines with a single blank line
$  cat -s temp1.txt   ←  Run it with the option “-s”.
A.    abc
B.   def
C.    ghi
  A blank line becomes  one line.
D.
タイトルとURLをコピーしました