The last
command in Bash is used to display a list of the most recent logins to the system. It reads from the /var/log/wtmp
file, which records all logins and logouts, allowing users to track who accessed the system and when.
The basic syntax of the last
command is as follows:
last [options] [username]
-a
: Show the hostname on the last line.-n [number]
: Limit the output to the specified number of entries.-x
: Show system shutdown entries and run level changes.-R
: Suppress the display of the hostname.-F
: Display the full login and logout times.last
last -n 5
last username
last -a
last -F
last -x
last -n 10
to quickly check the last 10 login attempts, which is useful for a quick security review.last -a -n 5
to see the last 5 logins with hostnames.