QA Graphic

Last Command

UNIX command to see the last login

Hello, Mac enthusiasts! Today, we're diving into a powerful yet often overlooked command-line tool that comes pre-installed on your Mac: the 'last' command. This nifty utility allows you to view the login history on your Mac, which can be incredibly useful for security monitoring or just satisfying your curiosity.

What is the 'last' command?

The 'last' command is a Unix utility that reads the system's wtmp file, which keeps a record of all logins and logouts. It's a simple yet powerful tool for tracking user activity on your Mac.

How to use the 'last' command

  1. Open Terminal (you can find it in Applications > Utilities or use Spotlight to search for it).

  2. Type last and press Enter.

  3. You'll see a list of login sessions, starting with the most recent. Each line shows:

    • Username
    • Terminal or console used (e.g., console, ttys000)
    • IP address (if logged in remotely)
    • Login date and time
    • Logout time (or "still logged in" if the session is active)

Useful variations

  • last -10: Shows only the last 10 login sessions
  • last username: Shows login history for a specific user
  • last reboot: Shows system reboot history
  • last -t YYYYMMDDHHMMSS: Shows logins before a specific date/time
  • last -F: Displays full login and logout times

Pro tip: Combining with other commands

You can combine 'last' with other Unix commands for more specific information. For example:

  • last | grep "root": Shows only root user logins
  • last | awk '{print $1}' | sort | uniq: Lists unique users who have logged in

last Crash
Use GREP to see when the computer last crashed!

Why is this useful?

  1. Security: Regularly checking login history can help you spot unauthorized access attempts.
  2. Troubleshooting: It can help identify when issues started occurring.
  3. Usage patterns: Understand how and when your Mac is being used.

Remember, the 'last' command is just one of many powerful tools available in the macOS Terminal. Stay tuned for more tips on leveraging these hidden gems to supercharge your Mac experience!

 

About

A Mac veteran since 1989, I'm here to share my experience with tips and tricks every Friday. Witnessing the evolution of Mac software and hardware firsthand, I've gained a deep understanding of how these machines work and can help you troubleshoot any issues that may come up.

Schedule

FridayMacintosh
SaturdayInternet Tools
SundayOpen Topic
Monday Media Monday
TuesdayQA
WednesdayKeyboard Maestro
ThursdayGluten Free