The Wayback Machine - https://web.archive.org/web/20230512155804/https://www.geeksforgeeks.org/last-command-in-linux-with-examples/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

last command in Linux with Examples

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The last command in Linux is used to display the list of all the users logged in and out since the file /var/log/wtmp was created. One or more usernames can be given as an argument to display their login in (and out) time and their host-name.

Syntax:

last [options] [username...] [tty...]

Example:

Options:

  • -[number]: This option is used to specify the number of lines to display.

    Example:

    last -5

    Output:

  • -R: This option is used to hide the host-name field.

    Example:

    last -R basil

  • -F: This option is used to display the login and logout time including the dates.

    Example:

    last -F

  • -a: This option is used is to display the host-name in the last column.

    Example:

    last -a
  • -s, -t: This option is used to display within a specific time period.(-s) since and (-t) until, these commands are used to frame the time period.

    Example:

    last -s yesterday -t today

    The valid formats for the above commands are:

    YYYYMMDDhhmmss
    YYYY-MM-DD hh:mm:ss
    YYYY-MM-DD hh:mm      (seconds will be set to 00)
    YYYY-MM-DD            (time will be set to 00:00:00)
    hh:mm:ss              (date will be 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
    
  • -d: This option is used to translate the IP address back into its host-name.

    Example:

    last -d
  • -x: This option is used to display information like system down entries and run level changes.

    Example:

    last -x
  • -w: This option is used to display full user and domain names.

    Example:

    last -w basil
  • –help: This option is used to display help regarding all options belonging to the last command.

    Syntax:

    last --help
My Personal Notes arrow_drop_up
Last Updated : 22 May, 2019
Like Article
Save Article
Similar Reads