Home » Questions » Computers [ Ask a new question ]

How can I find the number of users online in Linux?

How can I find the number of users online in Linux?

How can I see how many people are logged on to a Linux machine? I know the 'users' command shows all the people logged in but I need a number. Is there a switch for users that I am missing in the man page? I thought of using the grep -c command, but there must be something that is the same in each username for this to work. Is there an easier way?

Asked by: Guest | Views: 83
Total answers/comments: 5
Guest [Entry]

"You are looking for the wc (word count) command.

Try this:

users | wc -w"
Guest [Entry]

"Open a shell and type:

who -q

The last line will give you a count.


(sigh) I misunderstood the question. Here's a somewhat brute-force approach:

To see unique user names:

who | awk '{ print $1 }' | sort | uniq

To see a count of unique users:

who | awk '{ print $1 }' | sort | uniq | wc -l"
Guest [Entry]

"number of the users currently logged in:

who |cut -c 1-9 |sort -u |wc -l

the above buta with their account name:

who |cut -c 1-9 |sort -u |tee /dev/tty |wc -l"
Guest [Entry]

"who | cut --delimiter=' ' -f 1 | sort -u | wc -l

Who prints out the list, cut removes everything but the first row, sort -u sort it and removes duplicates and wc -l counts the lines. Works fine for me on ubuntu/bash :)"
Guest [Entry]

"You can simply use w (/usr/bin/w on my Red Hat based system) or uptime, they show the actual number of logged in users.


22:40:38 up 3 days, 22 min, 1 user, load average: 0.02, 0.01, 0.00
manuel pts/0 pc-manuel 09:35 0.00s 0.07s 0.00s /usr/bin/screen -xRR


22:39:18 up 3 days, 21 min, 1 user, load average: 0.08, 0.02, 0.01"