lastlog Command in Linux with Examples

This tutorial explains Linux “lastlog” command, options and its usage with examples.

lastlog – examine lastlog file

Description :

lastlog formats and prints the contents of the last login log /var/log/lastlog file . The login-name, port, and last login time will be printed. The default (no flags) causes lastlog entries to be printed, sorted by the numerical UID.

Usage :

lastlog [<-u|--user> login-name] [<-t|--time> days] [<-h|--help>]

Options :


-u, –user login-name
It will cause the lastlog record for login-name only to be printed
-t, –time days
It will cause only the lastlogins more recent than mentioned days to be printed
-h, –help
It prints a one-line help message and exit.

Note :
The -t flag overrides the use of -u.
If the user has never logged in the message “**Never logged in**” will be displayed instead of the port and time.

Examples :

Note: Join free Sanfoundry classes at Telegram or Youtube

1. Simple usage

$ lastlog
Username         Port     From             Latest
root             tty1                      Thu Apr 26 15:23:50 +0530 2014
daemon                                     **Never logged in**
bin                                        **Never logged in**
sys                                        **Never logged in**
sync                                       **Never logged in**
abc1             tty1                      Sat Apr 26 22:10:36 +0530 2014
pdnsd                                      **Never logged in**
sshd                                       **Never logged in**
messagebus                                 **Never logged in**
bind                                       **Never logged in**
abc2             tty1                      Sat Apr 26 19:55:22 +0530 2014

2. Display lastlog information for a particular user

$ lastlog -u abc1
Username         Port     From             Latest
abc1             tty1                      Sat Apr 26 22:10:36 +0530 2014

3. Display recent login information

$ lastlog -t 1

Displays the login information, 1 day ago.

Since no login happened, the lastlog command returned no output.


Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.