Score:0

How to use last to see how many times users logged in?

jp flag

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
ar flag
Which distro and version of Linux are you using?
ar flag
`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.
user10489 avatar
in flag
Note that last only gives logins since the last time wtmp was rotated.
Usermaxn avatar
jp flag
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 avatar
jp flag
```last | cut -c 1-8 | sort | uniq -c | sort -r``` worked great. thanks.
ar flag
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.
Usermaxn avatar
jp flag
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.
Score:0
jp flag

thanks to @user68186

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

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.