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?
Best Answer
Assuming you are using the version of
last
in theutil-linux
package:or even:
or
last
has-s
(--since
) and-t
(--until
) options for restricting output to certain dates and times. Thesort -k1,1 -u
does a unique sort on just the first field oflast
's output.See
man last
, especially search forTIME FORMATS
for more details.