Let’s learn about the last command in Linux with examples and options will show a listing of a last logged in users.
We will also learn last, lastb, and lastlog command which work somewhat different.
All the last logged in users are stored in /var/log/wtmp and the failed logged in users are stored in /var/log/btmp.
How to check the last logged in Users using the last command in Linux.

Command # last
So the last command is used to see the last logged in users, there are some fields which are displayed.
- user.
- TTY.
- HOST.
- Timestamp and login time.
- logout time.
How to check the top 10 lines from the last command.

So if we want to see the 10 lines use -n option with the last command.
Command # last -n 10
If you want to see 15 lines then use # last -n 15.
How to print host in the last column using the last command.
Suppose we want the host in the last column then we will use -a option.

Command # last -a
On the above example we have used -n 5 -a that means to print the 5 lines with the host at the last column.
How to suppress the host using the last command.
What if we do not want to see the host then use -R option with the last command.

Command # last -R
We can see the host field in the first example and used -R option in the second example to suppress the host
How to check the last login and log out time using the last command in Linux.

Command # last -F
So, when we use -F option it will print the full login and logout time of the users.
How to check today logged in Users using the last command.

Command # last -s today
We will use -s option and today as an argument to see the today last logged in users.
If we have to see the last logged in users since yesterday then use -s yesterday.

Command # last -s yesterday
-s option is since and -t option is until we can use this as a range as -s since -t until let’s see the example.

Command # last -s 2020-07-02 -t 2020-07-05
So, we have checked the logged-in users from 2nd July 2020 until 5th July 2020.
Command # last -s 2020-07-02 -t now
And in the above example, we have used “now” argument with -t option “now” will use the current timestamp of your system.
How to display full username using the last command in Linux.

Command # last -w
When we use the last command then it doesn’t show us a full username, and while using -w option will print the full username.
How to check the last failed logged in Users using the lastb command in Linux.

Command # lastb
The lastb command is used to check the failed logged in users in the server.
How to check the recent logged in Users using the lastlog command in Linux.

Command # lastlog
This lastlog command used to check the most recent logged in users. If you want to see the recent logged in users for 2 days, 3 days and 4 days.

Command to see the recent logged-in Users in 2 days # lastlog -t 2
Command to see the recent logged-in Users in 3 days # lastlog -t 3
Command to see the recent logged-in Users in 4 days # lastlog -t 4
But what if we want to see the last logged in users before 2 days ago, so use -b option.

Command # lastlog -b 2
How to check the recent logged in for the specific user the lastlog command in Linux.
So let’s check the recent logged in for the specific users using – u option.

Command # lastlog -u test
suppose we have to check the recent login for the user “test” then we will use the above example.
If we have the “id” of the user then we can use that id with the -u option, let’s see the example.

Command # lastlog -u 27
So the 27 id is of MySQL user, and now see how we can use id between the range.

So we have the user id 1000, 1001, and 1002 then use -u option and 1000-1002.

Command # lastlog -u 1000-1002
User id 1000 is tastethelinux, 1001 is of tla, and 1002 is of the test user.
How to clear the recent logged in users record using lastlog command in Linux.
So to clear the recent logged in users record use -C option with lastlog command.

Command # lastlog -C -u test
So we have clear the record of the user test with the help of lastlog command.
A cheat sheet of the last/lastb/lastlog command.
How to check the last logged in Users using the last command in Linux. Example: # last
How to check the top 10 lines from the last command. Syntax: # last -n [number_of_line] Example: # last -n 10
How to print host in the last column using the last command. Example: # last -a
How to suppress the host using the last command. Example: # last -R
How to check the last login and log out time using the last command in Linux. Example: # last -F
How to check today logged in Users using the last command. Syntax: # last -s [time] Example: # last -s today # last -s yesterday
How to check logged in Users in range using the last command. Syntax: # last -s [time] -t [time] Example: # last -s 2020-07-02 -t 2020-07-05 # last -s 2020-07-02 -t now
How to display full username using the last command in Linux. Example: # last -w
How to check the last failed logged in Users using the lastb command in Linux. Example: # lastb
How to check the recent logged in Users using the lastlog command in Linux. Example: # lastlog # lastlog -t 2 **See the recent logged-in Users in 2 days** # lastlog -t 3 **See the recent logged-in Users in 3 days** # lastlog -t 4 **See the recent logged-in Users in 4 days** # lastlog -b 2 **See the recent logged-in Users before 2 days ago*
How to check the recent logged in for the specific user the lastlog command in Linux. Syntax: # lastlog -u [user]/[id]/[id]-[id] Example: # lastlog -u test # lastlog -u 27 # lastlog 1000-1002
How to clear the recent logged in users record using lastlog command in Linux. Syntax: # lastlog -C -u [user] Example: # lastlog -C -u test
[wp_quiz id=”3482″]
Want to learn about the more basic command the refer the link you can also practice the basic command refer this link.