Analyze Specific last Command Entries
In this step, you will learn how to analyze specific entries in the output of the last
command.
The last
command can provide detailed information about each login session, including the username, terminal, IP address, login time, and logout time. You can use this information to investigate specific user activities or system events.
For example, let's say you want to analyze the login session of the user labex
:
last labex
Example output:
labex pts/0 172.17.0.1 Fri Mar 31 10:23 still logged in
labex pts/0 172.17.0.1 Fri Mar 31 10:22 - 10:23 (00:00)
labex pts/0 172.17.0.1 Fri Mar 31 10:21 - 10:22 (00:01)
labex pts/0 172.17.0.1 Fri Mar 31 10:20 - 10:21 (00:01)
From this output, you can see that the user labex
has logged in four times on the current day. The first three sessions were short, lasting less than a minute each. The user is still logged in for the fourth session, which started at 10:23.
You can also use the last
command to investigate specific login sessions by providing the username and the terminal. For example:
last labex pts/0
Example output:
labex pts/0 172.17.0.1 Fri Mar 31 10:23 still logged in
labex pts/0 172.17.0.1 Fri Mar 31 10:22 - 10:23 (00:00)
labex pts/0 172.17.0.1 Fri Mar 31 10:21 - 10:22 (00:01)
labex pts/0 172.17.0.1 Fri Mar 31 10:20 - 10:21 (00:01)
This command will show only the login sessions for the user labex
on the terminal pts/0
.
By analyzing the last
command output, you can gain valuable insights into user activities and system events, which can be useful for troubleshooting, security monitoring, and system administration.