This tutorial explains Linux “lastlog” command, options and its usage with examples.
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 :
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.
- Practice Programming MCQs
- Check Information Technology Books
- Apply for Programming Internship
- Check Linux Books