"Last" command: How to show latest user login?
You can also use the command lastlog
command on Linux. It gives you more granular controls as to ranges of dates when looking through the logs of user logins.
excerpt from lastlog man page
lastlog - reports the most recent login of all users or of a given user
Example
To find out the users that have logged into a system in the last 100 days.
$ lastlog -b 0 -t 100
Username Port From Latest
sam pts/0 pegasus Wed Jan 8 20:32:25 -0500 2014
joe pts/0 192.168.1.105 Thu Dec 12 12:47:11 -0500 2013
This shows that the last times these users logged into this system. The range of time shows the last 100 days. Before today (-b 0
) and after 100 days ago (-t 100
).
You can also show all the users by omitting any range and just seeing every usre that's ever logged in, and the last time they logged in.
last
reads from a log file, usually /var/log/wtmp
and prints the entries of successful login attempts made by the users in the past. The output is such that the last logged in users entry appears on top. In your case perhaps it went out of notice because of this.
In order to check when was the file /var/log/wtmp
was written last, you can use stat
command:
stat /var/log/wtmp
In order to print the output in reverse, you can pipe output of last to GNU tac
(opposite of cat) as follows:
last | tac