System and processes
The last command
Shows the history of logins and logouts, and of reboots, by reading the wtmp log. It helps you know when the machine was used and spot unusual access. At the end, it shows since when the file holds data.
Most useful options
-n <n>Shows only the last n entries-f <archivo>Reads another log file, such as an old rotation (wtmp.1)-FShows full start and end dates, with the year-iShows the source IP instead of the host name-xAdds shutdowns and runlevel changes-wShows full user and host names, without cutting themCopy-ready examples
$ lastall the logins, most recent first.Example output
miguel tty2 tty2 Tue Nov 3 08:02 still logged in miguel pts/0 192.168.1.20 Mon Nov 2 18:40 - 19:12 (00:32) reboot system boot 6.8.0-45-generic Mon Nov 2 08:55 still running wtmp begins Sun Oct 4 16:11:38 2026
$ last -n 5only the last five.$ last -i miguelmiguel's sessions, with the IP he logged in from.$ last rebootthe boot history. 'still running' marks the current boot.Example output
reboot system boot 6.8.0-45-generic Mon Nov 2 08:55 still running
$ sudo last -x | grep -E 'shutdown|runlevel'shutdowns and runlevel changes, filtered.$ sudo last -f /var/log/wtmp.1reads the previous log rotation, from weeks ago.You can try them in the browser terminal: it does not touch your computer.
Typical mistakes
- last reads wtmp: it only records logins and logouts. Failed passwords are in btmp and are read with lastb.
- A session marked still logged in can be left over from an abrupt shutdown: it does not always mean someone is connected now.
- The history follows the machine clock: if the clock was wrong, the dates are wrong too.
- With -F, the dates include the year.
Differences from similar commands
- who: shows who is logged in right now. last shows the history.
- w: who is logged in right now and what each one is doing.
- journalctl: full systemd log, with sudo, sshd and more. last only reads wtmp.
Security
last reveals who logged in, when and from where: it is sensitive information. Do not paste it into screenshots or reports without removing IPs and names. And since root can edit wtmp, it is not conclusive proof.
Related commands
FAQ
How do I know when the machine was rebooted?
With last reboot. Each 'system boot' row marks a boot, and 'still running' marks the current one.
Why are there 'still logged in' sessions from yesterday?
Because the log never got the logout: the machine went down without closing the session, due to a power cut or a forced shutdown.
How do I see failed login attempts?
With lastb, which reads btmp. It usually needs root.
What does 'wtmp begins' mean?
It is the date of the first entry the file keeps. If it is recent, the log was rotated or cleared.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course