Enhancing Skills

last: Display the login history of users on the system

Command: last

The last command shows a list of the most recent logins to the system. It displays information about the username, the terminal used, the IP address or hostname of the remote system (if applicable), and the time and duration of each login session.


Sample Commands and Outputs:

  • last: Displays the login history of users. Sample Command and Output:
  $ last
  user1   tty1         192.168.1.10    Mon Aug  5 10:00:00 - 10:45:00  (00:45)
  user2   pts/0        192.168.1.11    Mon Aug  5 09:30:00 - 10:00:00  (00:30)
  reboot  system boot  192.168.1.1     Mon Aug  5 08:00:00 - 09:00:00  (01:00)

Description:

  • user1: Username of the logged-in user.
  • tty1: Terminal used for the login.
  • 192.168.1.10: IP address of the remote host (for remote logins).
  • Mon Aug 5 10:00:00 - 10:45:00: Login time and duration.
  • (00:45): Duration of the session.
  • last -a: Displays the hostname or IP address of the remote system in the last column. Sample Command and Output:
  $ last -a
  user1   tty1         Mon Aug  5 10:00:00 - 10:45:00  (00:45) 192.168.1.10
  user2   pts/0        Mon Aug  5 09:30:00 - 10:00:00  (00:30) 192.168.1.11
  reboot  system boot Mon Aug  5 08:00:00 - 09:00:00  (01:00) 192.168.1.1

Description:

  • -a: Includes the hostname or IP address of the remote system in the output.
  • last -n 5: Shows the last 5 login entries. Sample Command and Output:
  $ last -n 5
  user1   tty1         Mon Aug  5 10:00:00 - 10:45:00  (00:45)
  user2   pts/0        Mon Aug  5 09:30:00 - 10:00:00  (00:30)
  reboot  system boot Mon Aug  5 08:00:00 - 09:00:00  (01:00)

Description:

  • -n 5: Limits the output to the last 5 login entries.
  • last -x: Includes system shutdown entries in the output. Sample Command and Output:
  $ last -x
  user1   tty1         Mon Aug  5 10:00:00 - 10:45:00  (00:45)
  reboot  system boot Mon Aug  5 08:00:00 - 09:00:00  (01:00)

Description:

  • -x: Shows system shutdown and run level changes in addition to user logins.

Note: The last command is useful for monitoring user activity and system usage. It provides insights into login patterns and can help in troubleshooting and auditing system access.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.