Show only the five most recent login, logout, and reboot records from wtmp.
Which command is appropriate?
last -n 5 reads wtmp history and limits output to five records.
Detailed explanation
who -n 5Incorrect. who shows current sessions, not history.
Incorrect. who shows current sessions, not history.
w -n 5Incorrect. w shows current activity.
Incorrect. w shows current activity.
lastlog -n 5Incorrect. lastlog focuses on each user's latest login rather than the latest five records overall.
Incorrect. lastlog focuses on each user's latest login rather than the latest five records overall.
last -n 5Correct. It limits the historical output to five records.
Correct. It limits the historical output to five records.
Try it yourself
An example you can run in a temporary verification environment.
last --help 2>&1 | grep -E -- '-n|--limit' | head -n 1Expected result
件数制限に関するhelp行Key points
- last reads wtmp
- -n limits count
- who shows current sessions
Notes
- Environment: util-linux last help / 履歴変更なし
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.