Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

Use Last Command: How to Use the Last Command in Linux

Get a clear overview of Use Last Command: How to Use the Last Command in Linux, why it matters, and what readers should know.

Table of Contents

This updated guide examines Use Last Command: How to Use the Last Command in Linux and organizes the essential facts, background, and practical takeaways in clear American English.

  • Basic Linux commands everyone needs to know
  • How to take a screenshot of the login screen in Linux
  • How to remotely control Linux using a Windows computer

Wtmp file

Linux and other Unix-like operating systems such as MacOS manage very well in login. On the system, you can find a log of everything related to login, logout on the computer. This log file is called wtmp. W stands for When (when) or who (who). The tmp section may be short for temporary but may also be short for timestamp (timestamp).

We only need to know wtmp is a log that records all logon and logoff events on the computer. Viewing data in the wtmp log is the basic step in security. For a regular home computer, security is not an important issue, but it is also interesting to review the use of your computer.

Unlike other text-based log files in Linux, wtmp is a binary file. To access data in this file, you need to use the last command.

  • Basic file system in Unix / Linux

Last order

The last command reads data from the wtmp record and displays it in the terminal window. If typing last and pressing Enter , it will display all the records from the log file.

last

Use Last Command: How to Use the Last Command in Linux — contextual image 1

Each record from wtmp is displayed in the terminal window.

From left to right, each line contains:

  • Login username.
  • The device they logged in. Device item: 0 means login on the Linux computer itself.
  • IP address of login machine.
  • Login time and date stamp.
  • Time of the session

Use Last Command: How to Use the Last Command in Linux — contextual image 2

The last line tells us the date and time of the earliest recorded session in the log.

The login for fictitious user "reboots" is entered into the log every time the computer is started. The device field is replaced with the kernel version. The duration of the login session for these items represents the computer's uptime.

Show some specific lines

Using only the last command will display all the above information. If you want specific information, you can ask for last to provide the specific line number of the output. For example, if you want to see 5 lines, you need to type -5 with the last command.

last -5

Use Last Command: How to Use the Last Command in Linux — contextual image 3

The above command will show the first five lines of the log, this is the most recent data.

Use Last Command: How to Use the Last Command in Linux — contextual image 4

Display network name for remote users

The -d (Domain Name System) option requires last resolving the remote user's IP address into a host name or network name.

last -d

Use Last Command: How to Use the Last Command in Linux — contextual image 5

However, it is not always possible to convert IP addresses to network names, but the command will execute when possible.

Use Last Command: How to Use the Last Command in Linux — contextual image 6

Hide IP address and network name

If you are not interested in the IP address or network name, use the -R option (without the server name) to block this field.

Use Last Command: How to Use the Last Command in Linux — contextual image 7

This option will give you a more neat output, so it will be used in the examples below. If using last to determine unusual activity, you should not block this field.

Use Last Command: How to Use the Last Command in Linux — contextual image 8

Select the record by date

You can use the -s option (since) to restrict the output to only show log events that take place since a particular date.

If you only want to see the login events taking place from 26/5/2019, you will use the following command:

Use Last Command: How to Use the Last Command in Linux — contextual image 9

The output that displays the log with log events takes place from 00:00 on the day specified to the latest record on the log file.

Use Last Command: How to Use the Last Command in Linux — contextual image 10

Search within a specific time period

You can use -t (until) to specify an end date. This allows you to select a log file set that takes place at a specific time.

Use Last Command: How to Use the Last Command in Linux — contextual image 11

This command requires last retrieval and displays log log from 00:00 (dawn) day 26 to 00:00 (dawn) day 27. It limits the login session to take place only on the 26th

Use Last Command: How to Use the Last Command in Linux — contextual image 12

Format time and date

You can use time as well as dates with -s and -t options. Different time formats can be used with last options for dates and times:

  • YYYYMMDDhhmmss
  • YYYY-MM-DD hh: mm: ss
  • YYYY-MM-DD hh: mm - seconds are set to 00
  • YYYY-MM-DD - time is set to 00:00:00
  • hh: mm: ss - date is set to today
  • hh: mm - date will be set to today, seconds to 00
  • now
  • yesterday - time is set to 00:00:00
  • today - time is set to 00:00:00
  • tomorrow - time is set to 00:00:00
  • + 5min
  • -5days

These commands are tested on Ubuntu, Fedora and Manjaro distributions. These are derivatives of the Debian, RedHat and Arch distributions respectively.

last -R -s 2019-05-26 11:00 -t 2019-05-27 13:00

Use Last Command: How to Use the Last Command in Linux — contextual image 13

As you can see the above command does not return any records. Use the first date and time format from the list as the previous command returns records:

last -R -s 20190526110000 -t 20190527130000

Use Last Command: How to Use the Last Command in Linux — contextual image 14

Search in relative units

You also specify the time interval in minutes or days, relative to the current date and time. The following command we require a record from the previous 2 days until the previous day.

last -R -s -2days -t -1days

Use Last Command: How to Use the Last Command in Linux — contextual image 15

Yesterday, today and now

You can use yesterday and tomorrow to abbreviate for yesterday's date and today's date.

last -R -s yesterday -t today

Use Last Command: How to Use the Last Command in Linux — contextual image 16

Orders require records from the start date to the end date. It does not include records for the end date.

Use Last Command: How to Use the Last Command in Linux — contextual image 17

Now option is an abbreviation for 'today at the current time'. To see a login event that takes place from 00:00 (dawn) until the time when you use this command:

last -R -s today -t now

Use Last Command: How to Use the Last Command in Linux — contextual image 18

The above command will display all current login events, including those that are still logged in.

Use Last Command: How to Use the Last Command in Linux — contextual image 19

-P option

The -p (current) option allows you to find out who has logged in at a point in a specific time. If someone signs in to the computer at the time you specify, they will be listed.

If you specify a time without a date, the last command will default to you today (ie the date of using this command).

last -R -p 9:30

Use Last Command: How to Use the Last Command in Linux — contextual image 20

People still logged in without logout time; They are described as still logged in . If the computer has not been restarted since the time you specified it, it will be listed as still running .

Use Last Command: How to Use the Last Command in Linux — contextual image 21

If you use now with the -p option, you can detect who is logged in at the time you use the command.

last -R -p now

Use Last Command: How to Use the Last Command in Linux — contextual image 22

This is a slightly longer way when using the who command.

Use Last Command: How to Use the Last Command in Linux — contextual image 23

Lastb command

The lastb command reads data from the record called btmp. Lastb lists the failed login times. You can also use the options of last with this command. Because login failed, the time will be 00:00.

You must use sudo with lastb .

Use Last Command: How to Use the Last Command in Linux — contextual image 24

Knowing who has logged in to your Linux computer is very useful and incorporating information about unsuccessful logins will help you take the first steps in investigating computer intrusions. doubt.

FAQ

What is Use Last Command: How to Use the Last Command in Linux about?

It provides a structured overview of use last command, explains the main context, and highlights practical takeaways for readers.

Why does this topic matter?

Understanding the main concepts helps readers evaluate the issue, avoid common mistakes, and make better-informed decisions.

How should readers use this information?

Use the guidance as a practical starting point, confirm details that may have changed, and follow current product, safety, or security recommendations.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.