display users that logged in since a date using last

8,698

Assuming you are using the version of last in the util-linux package:

last -s '2015-11-01'  | sort -k1,1 -u

or even:

last -s '-1 month'  | sort -k1,1 -u

or

last -s '2015-07-01' -t '2015-07-31' | sort -k1,1 -u

last has -s (--since) and -t (--until) options for restricting output to certain dates and times. The sort -k1,1 -u does a unique sort on just the first field of last's output.

See man last, especially search for TIME FORMATS for more details.

Share:
8,698

Related videos on Youtube

jonny
Author by

jonny

Updated on September 18, 2022

Comments

  • jonny
    jonny over 1 year

    I am trying to display the user name of the accounts that have logged in during the past month using the last command.

    At the moment I have this

    last | awk '{print $1, $4 ,$5 ,$6}' | grep -B 10 Jul | sort -u -t' ' -k1,1
    

    As the users who have logged in most recently are displayed higher in the list, I am trying to grep for the month, then display that line and the lines above it and delete duplicate usernames. But it doesn't seem to be working. Any ideas?

    • G-Man Says 'Reinstate Monica'
      G-Man Says 'Reinstate Monica' over 8 years
      (1) Your question is puzzling, you say "since a month" (now edited to "during the past month"), and it is currently November, but you're grepping for "Jul".  (2) I don't understand why you're saying -B 10; please try to explain that better.  (3) "It doesn't seem to be working" is very vague.  What does it do?  (4) Have you tried breaking it down into pieces?  For example, do last | awk '{print $1, $4, $5, $6}' and see whether the output is what you expect, and then work from there.
    • Vinz
      Vinz over 8 years
      Did you look at last -t ?
    • muru
      muru over 8 years
      Does last show any entries for July?