last

2024-12-22

Understanding the last Command’s Functionality

The last command displays a list of recent logins and system events. By default, it shows information from the /var/log/wtmp file (or its symbolic link, often /var/run/utmp), which records user logins and system boot/shutdown events. The output provides details, including:

Basic Usage: Viewing Recent Logins

The simplest way to use last is to execute the command without any arguments:

last

This will display the most recent login entries. The number of entries shown defaults to system settings but can be controlled (see options below).

Refining Your Search with Options

The last command offers many useful options to customize the displayed information:

last -n 10
last john.doe

This will show all login attempts for the user “john.doe.”

last tty1

Combining Options for Powerful Analysis

The true power of last lies in combining these options. For instance, to view the last 5 logins for the user “alice” from a specific TTY, you would use:

last -n 5 alice pts/0

To see only the last 20 login entries excluding boot and shutdown:

last -n 20 -i

Inspecting a custom log file for a particular user:


last -f /path/to/custom.log user1

By mastering these options, you gain a granular level of control over the system login history analysis. This allows for efficient investigation of security breaches, performance issues related to user activity, and troubleshooting login problems. Remember to use appropriate caution when examining system logs and always respect file permissions.