This article originally appeared in TidBITS on 2014-02-17 at 1:49 p.m.
The permanent URL for this article is:
Include images: Off

Exploring Your Mac’s Restarts via the Command Line

by Josh Centers

Curious to know when you last had to restart your Mac, or how often you’ve been rebooting? It turns out that there’s a command line invocation to report on that information. What’s the utility of such details? If you’re troubleshooting flaky hardware, perhaps you want to document how often you’re having to restart, or you might want to look up the exact date of a recent kernel panic when working with tech support.

If you’re intimidated by Unix, don’t worry, as this one is as simple as it gets. Open Terminal from /Applications/Utilities, and type last reboot and press Return. You’re presented with a log of all the times you restarted your Mac, back to when the log begins. Mine dates only to October 2013, whereas Adam Engst’s includes 70 restarts since May 2013, and shows several instances when he was restarting repeatedly while trying to isolate a bad DIMM.

[image link] [1]

Technically, the last command displays the sessions of specified users, so you could also type last shortname — where shortname is the short name of a user account — to see all the times that particular account logged in, or just last by itself to show all sessions. reboot is a pseudo-user, as is shutdown, so last shutdown displays all the logged shutdown events.

Want to create a permanent record of your restarts? Try this command:

last reboot > ~/Desktop/reboot-log.txt

That tells your Mac to run the last reboot command, and then send its output to a new file called reboot-log.txt on your Desktop. And if you wanted to keep recording restarts to this file from the command line, you would instead use:

last reboot >> ~/Desktop/reboot-log.txt

That’s the same command, but with two angle brackets, which specify that the output should be appended to the end of the existing file, instead of overwriting the one that’s already there. Give it a try to see what it does.

While on the subject, as long as you’re in Terminal, try the uptime command to see how long your computer has been running since the last restart.

[image link] [2]