How to check the last time system was rebooted on Linux

Question: Is there a way to quickly check how long a Linux system has been running? That is, how can I find out the last time a Linux system was rebooted?

There are several ways to find out the last system reboot time,

Method One

The first method is to use last command.

$ last reboot

This command actually shows system uptime for the last few days. Originally the last command is designed to show login history of a particular user. In Linux, a special "pseudo user" named reboot automatically logs in to the system right after the system has rebooted. Thus by checking the login history of reboot user, you can check the last reboot time.

Method Two

Another command to check the time of last system boot is to use who command with '-b' option.

$ who -b

Method Three

You can also use uptime command to deduce last reboot time. The uptime command shows you the current time, as well as how long the system has been running. From this information, you can calculate the time when the system was last booted.

$ uptime

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.

2 thoughts on “How to check the last time system was rebooted on Linux

  1. The "who -b " seems more reliable than "last reboot" as /var/wtmp might get archived, as seems to have happened to me :

    krish@xanadu:~$ who -b
    system boot 2014-07-19 15:43
    krish@xanadu:~$ last reboot

    wtmp begins Sat Aug 2 18:10:55 2014
    krish@xanadu:~$ uptime
    15:54:02 up 26 days, 11 min, 11 users, load average: 1.13, 1.14, 0.81
    krish@xanadu:~$ date
    Thu Aug 14 15:54:06 IST 2014

    uptime is a thin (formatting) wrapper around : /proc/uptime

    A small python snippet below (which requires installation of dateutil.tz) which will print uptime and boot time.

    # ================================================
    #!/usr/bin/env python

    import sys
    import datetime
    from datetime import timedelta
    from dateutil.tz import tzlocal

    with open('/proc/uptime', 'r') as f:
    uptime_seconds = int(float(f.readline().split()[0]))
    uptime_timedelta = timedelta(seconds = uptime_seconds)
    uptime_string = str(uptime_timedelta)
    today = datetime.datetime.now(tzlocal())
    format = "%a %d %b %Y %H:%M:%S %Z"
    boot_time = (today - uptime_timedelta).strftime(format)
    now = today.strftime(format)

    print "Uptime", uptime_string
    print "Boot time", boot_time
    # ================================================

Leave a comment

Your email address will not be published. Required fields are marked *

Current ye@r *