0

I need to see how many times users logged in.

I used last | sort | uniq -c but it gave me bad data

I need to sort them by number of times they logged in and only show username and number of time.

for example:

username       number of logins
userb          36
usera          12
userd          12
userc          8
Nmath
  • 12,105
  • 8
  • 25
  • 54
Usermaxn
  • 197
  • 6
  • Which distro and version of Linux are you using? – user68186 Feb 04 '23 at 20:24
  • 1
    `last | cut -c 1-8 | sort | uniq -c` does the job but does not the format it the way you want. it also reports blank lines, reboots etc. `awk` will do the job better. – user68186 Feb 04 '23 at 20:54
  • Note that last only gives logins since the last time wtmp was rotated. – user10489 Feb 04 '23 at 21:06
  • I have bash shell. as for what distro its a custom one that my work uses. though it is up to date. anything that worked on my ubuntu has worked there too. – Usermaxn Feb 04 '23 at 21:08
  • ```last | cut -c 1-8 | sort | uniq -c | sort -r``` worked great. thanks. – Usermaxn Feb 04 '23 at 21:12
  • Questions about custom distros that are not official Ubuntu (or it's flavors) are off topic here. Please frame your question for your Ubuntu computer. – user68186 Feb 04 '23 at 21:23
  • it worked on my official ubuntu 22.04. and I tested it on my work server and it worked there too. I looked at it and it seems to be ubuntu 18 server. – Usermaxn Feb 05 '23 at 00:59

1 Answers1

0

thanks to @user68186

the answer is last | cut -c 1-8 | sort | uniq -c | sort -n -r

Usermaxn
  • 197
  • 6