About nixCraft

Linux last reboot time and date find out

Posted by Vivek Gite [Last updated: December 21, 2007]

So how do you find Linux / UNIX system last reboot or shutdown date and time? The last utility will either list the sessions of specified users, ttys, and hosts, in reverse time order, or list the users logged in at a specified date and time. Each line of output contains the user name, the tty from which the session was conducted, any hostname, the start and stop times for the session, and the duration of the session.

who command

You need to use who command, to print who is logged on. It also displays the time of last system boot. Use last command to display system reboot and shutdown date and time.
$ who –b
Output:

system boot  Apr 30 15:08

Use last command to display listing of last logged in users and system last reboot time and date:
$ last reboot | less
Or better try:
$ last reboot | head -1
Output:

reboot   system boot  2.6.15.4         Sun Apr 30 15:08 - 16:22  (01:13)

last command searches back through the file /var/log/wtmp and displays a list of all users logged in (and out) since that file was created. The pseudo user reboot logs in each time the system is rebooted. Thus last reboot command will show a log of all reboots since the log file was created.

To display last shutdown date and time use following command:
$ last -x|grep shutdown | head -1
Output:

shutdown system down  2.6.15.4         Sun Apr 30 13:31 - 15:08  (01:37)

Where,

For more information read last command man page.

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. jamshid Says:

    On my FC5 system instead of
    last reboot | head -1
    I can type
    last reboot -1

  2. diana Says:

    i couldn’t find out the error. please help me.

    #Send list of users logged on to server via email
    59 11 * * * last | grep date ‘+%a %b %d’ > /tmp/users.out ; mail -s “Users Logged Today” ephrondiana@gmail.com

    when i tried to execute,
    $ last |grep date ‘+%a %b %d’
    i got no such file or directory error.

  3. vivek Says:

    Should be..

    59 11 * * * last | grep $(date '+%a %b %d') > /tmp/users.out ; mail -s “Users Logged"
  4. diana Says:

    thanks a lot vivek.i din’t expect this much fast reply.But unfortunately when i execute,
    $ last | grep $(date ‘+%a %b %d’)
    i couldn’t get anything.Please help

  5. vivek Says:

    My bad…I forgot to include double quote …

    59 11 * * * last | grep "$(date '+%a %b %d')" > /tmp/users.out ; mail -s “Users Logged"

    Also you may wanna try out:

    last -t yyyymmddhhmmss

    HTH

  6. diana Says:

    Thanks vivek.its working great…..

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , , , , , , , ,

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.