The last command in Linux is used to display the list of all the users logged in and out since the file /var/log/wtmp was created. One or more usernames can be given as an argument to display their login in (and out) time and their host-name.
last [options] [username...] [tty...]
- -[number]: This option is used to specify the number of lines to display.
- -R: This option is used to hide the host-name field.
last -R basil
- -F: This option is used to display the login and logout time including the dates.
- -a: This option is used is to display the host-name in the last column.
- -s, -t: This option is used to display within a specific time period.(-s) since and (-t) until, these commands are used to frame the time period.
last -s yesterday -t today
The valid formats for the above commands are:
YYYYMMDDhhmmss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm (seconds will be set to 00) YYYY-MM-DD (time will be set to 00:00:00) hh:mm:ss (date will be set to today) hh:mm (date will be set to today, seconds to 00) now yesterday (time is set to 00:00:00) today (time is set to 00:00:00) tomorrow (time is set to 00:00:00) +5min -5days
- -d: This option is used to translate the IP address back into its host-name.
- -x: This option is used to display information like system down entries and run level changes.
- -w: This option is used to display full user and domain names.
last -w basil
- –help: This option is used to display help regarding all options belonging to the last command.