
Linux Command Line
The ‘last’ command in Linux is a useful tool for system administrators and users to view the history of user logins and logouts on a system. This command can provide valuable information about when and how often users are accessing a system, which can be useful for auditing and security purposes.
When to use the ‘last’ command?
- To view the history of logins and logouts on a Linux system
- To check when a specific user last logged in
- To check if there are any suspicious login attempts on the system
How to use the ‘last’ command
The basic syntax of the ‘last’ command is:
last [options] [username]
When run without any options or arguments, the ‘last’ command will display a list of all users who have logged in and out of the system, in reverse chronological order. The list will include the user’s username, the date and time of their login or logout, and the IP address or hostname of the system they logged in from.
Example:
To view the history of a specific user, you can specify their username as an argument to the ‘last’ command.
Example:
The ‘last’ command also supports various options that can be used to customize the output. Some commonly used options are:
- -n [number]: Display the last [number] entries
- -x: Display system shutdown and reboot records
- -R: Display the hostname instead of the IP address
Example:
The ‘last’ command is a powerful tool for viewing user login and logout history on a Linux system. It is useful for monitoring user activity, troubleshooting login issues, and identifying suspicious login attempts. With the variety of options and arguments available, it can be easily customized to suit specific needs.
See our list of 75 Linux commands you should know about.