Skip to content

last MacOS command

The last command in MacOS is a useful tool for system administrators and users to view a list of previously logged in users, along with information such as their username, terminal from which they logged in, IP address, time, and date of their last login. This command provides insights into user activity on the system and can be used for security and troubleshooting purposes. By utilizing the last command, users can track login history, identify unauthorized access, and monitor user activity effectively.

Terminal window
last [options] [parameters]
OptionDescription
-tShow time of the last reboot
-RShow the host name and port number of remote logins
-yHide the host name and port number of remote logins
-n linesRestrict the output to the last ‘lines’ number of entries
ParameterDescription
usernameShow the entries for a specific user
ttyShow the entries associated with a specific terminal device
hostnameShow the entries associated with a specific hostname
TTShow entries associated with a specific terminal name
Terminal window
last

Displays a list of previous user logins on the system.

Display the last 10 logins in reverse order

Section titled “Display the last 10 logins in reverse order”
Terminal window
last -n 10 -R

Displays the last 10 user logins in reverse order with hostname and timestamps included.

Terminal window
last -x

Displays reboot, shutdown, and system runlevel change history.

Display the last 5 logins with IP addresses

Section titled “Display the last 5 logins with IP addresses”
Terminal window
last -n 5 -a

Shows the last 5 user logins along with corresponding IP addresses.

Terminal window
last -xF | head -1

Shows the last time the system was rebooted.

Terminal window
lastb -a

Displays a list of unsuccessful login attempts with source IP address information.

To use the last command in MacOS, execute the following command:

Terminal window
last

How to display the last logged in users on MacOS?

Section titled “How to display the last logged in users on MacOS?”

To display the list of last logged in users on MacOS, use the following command:

Terminal window
last

How to show full user login history with last in MacOS?

Section titled “How to show full user login history with last in MacOS?”

To show the full history of user logins with last in MacOS, you can use the following command:

Terminal window
last -F

How to filter the output of last by username in MacOS?

Section titled “How to filter the output of last by username in MacOS?”

To filter the output of the last command by a specific username in MacOS, use the following command:

Terminal window
last username

How to limit the number of lines displayed with last in MacOS?

Section titled “How to limit the number of lines displayed with last in MacOS?”

To limit the number of lines displayed by the last command in MacOS, you can use the -n option followed by the number of lines you want to display. For example:

Terminal window
last -n 10

How to display the shutdown history with last in MacOS?

Section titled “How to display the shutdown history with last in MacOS?”

To display the shutdown history using the last command in MacOS, you can execute the following:

Terminal window
last -x shutdown

How to show the last system boot time with last in MacOS?

Section titled “How to show the last system boot time with last in MacOS?”

To show the last system boot time with the last command in MacOS, you can use the following command:

Terminal window
last -x boot

How to view specific terminal logins with last in MacOS?

Section titled “How to view specific terminal logins with last in MacOS?”

To view the logins for a specific terminal with the last command in MacOS, you can specify the terminal name after the command, for example:

Terminal window
last console
  • View the last few lines of a file
  • Repeat the last command
  • Quickly check the result of the previous command
  • Investigate the history of executed commands