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?
linux
add a comment |
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?
linux
add a comment |
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?
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?
linux
linux
edited Feb 14 '16 at 0:17
Jamal
4561617
4561617
asked Jul 26 '09 at 3:26
add a comment |
add a comment |
13 Answers
13
active
oldest
votes
You are looking for the wc
(word count) command.
Try this:
users | wc -w
note that this approach (an who/w solutions) show only users logged in, not necessarily active users (i.e. users that start a process and then logout leaving the running process behind). Just to give a heads up about the difference.
– estani
Mar 18 '13 at 13:45
add a comment |
Classically, the command is 'who' rather than 'users', but 'who' gives you more information. Looking back at the original Unix articles (mid-70s), the example would have been:
who | wc -l
Using 'wc -l' counts lines of output - it works with both 'users' and 'who'. Using '-w' only works reliably when there is one word per user (as with 'users' but not with 'who').
You could use 'grep -c' to count the lines. Since you are only interested in non-blank user names, you could do:
who | grep -c .
There's always at least one character on each line.
As noted in the comments by John T, the users
command differs from who
in a number of respects. The most important one is that instead of giving one name per line, it spreads the names out several per line — I don't have a machine with enough different users logged in to test what happens when the number of users becomes large. The other difference is that 'who' reports on terminal connections in use. With multiple terminal windows open, it will show multiple lines for a single user, whereas 'users' seems to list a logged in user just once.
As a consequence of this difference, the 'grep -c .
' formulation won't work with the 'users' command; 'wc -w
' is necessary.
small nitpick - the users command does not print 1 line per user, it just prints id's sequentially, so grep -c . would not work in this case. Smart thinking though.
– John T
Jul 26 '09 at 3:59
this also means that wc -l will not work with the users command, as shown here: i26.tinypic.com/4pw0vd.png
– John T
Jul 26 '09 at 4:11
@John T: oh - well, given screen shot, you're correct. I tested 'users' on MacOS X - but with just one user logged in. When I double checked with a second user logged in, I see the 'all on one line' behaviour.
– Jonathan Leffler
Jul 26 '09 at 5:52
1
to simulate more users you can SSH into your own box :)
– John T
Jul 26 '09 at 5:59
Thank you for this valuable information, although I wanted to stick with the "users" command. Also upvoted you, thanks.
– Anonymous
Aug 1 '09 at 23:54
add a comment |
Open a shell and type:
who -q
The last line will give you a count.
EDIT:
(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
that counts all logins of the same user in the total.
– hayalci
Jul 26 '09 at 18:56
check the re-edit, I think you'll find that the new answers address that.
– Avery Payne
Jul 27 '09 at 15:33
This still doesn't work, uniq only removes duplicate successive lines, you need to sort the output of who first.
– theotherreceive
Jul 27 '09 at 18:10
that's what I get for posting answers at 1am. (sigh) fixed.
– Avery Payne
Jul 27 '09 at 19:37
add a comment |
Do you want to see the number of sessions, or the number of actual users?
$ who
andrew tty1 2009-07-26 15:31 (:0)
andrew pts/0 2009-07-27 00:11 (:0.0)
andrew pts/1 2009-07-27 01:58 (:0.0)
That's on my laptop, so i'm the only user, but i'm logged on three times.
$ who | wc -l
3
$ users | wc -w
3
It is fairly easy to filter out these duplicates though to get the number of actual users.
$ users | tr ' ' 'n' | sort -u
andrew
$ users | tr ' ' 'n' | sort -u | wc -l
1
add a comment |
Here's a bash version of tink's great awk post:
set $(users)
declare -A user
for u ; do ((user[$u]++)) ; done
for key in "${!user[@]}" ; do echo "$key: ${user[$key]}" ; done | column -t | sort -nk 2
Ok, it's a little bit longer, but was worth finding this one ... :).
While testing, do before next attempt:
shift $# # clear positional parameters
unset user # remove associative array variable
add a comment |
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
add a comment |
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 :)
add a comment |
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.
w:
v
22:40:38 up 3 days, 22 min, 1 user, load average: 0.02, 0.01, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
manuel pts/0 pc-manuel 09:35 0.00s 0.07s 0.00s /usr/bin/screen -xRR
uptime:
v
22:39:18 up 3 days, 21 min, 1 user, load average: 0.08, 0.02, 0.01
add a comment |
And a method that uses only one pipe...
users | awk '{for(i=1;i<=NF;i++){a[$i]++}}END{for(i in a){print i"t"a[i]}}'
:}
add a comment |
http://www.gnu.org/software/coreutils/manual/html_node/who-invocation.html
"who" prints information about users who are currently logged on. Synopsis:
who [option] [file] [am i]
add a comment |
You could always download the free tool for unix called TOP. It produces a list of the users and also what they are doing on the system at the time and will continue to update as long as it is running.
It is located at http://www.unixtop.org/
It has many command line switches so you should be able to extract the information you are looking for.
I've yet to find a linux distro that doesn't include top by default, let alone not have an option to install it from packages.
– theotherreceive
Jul 27 '09 at 1:32
add a comment |
who | cut -d ' ' -f1 | uniq | wc -l
2
This seems like a minor variation of Kim's answer, and it contains no explanation. It might be more appropriate as a comment on that answer (which requires a little more rep). The intention is that each answer provide a solution that is substantively different from what has already been contributed.
– fixer1234
Feb 1 at 7:20
add a comment |
If you are looking for the total number of users logged in and logged off in a proper sequence, the best command to run is
cat -n /etc/passwd
2
No, that's not what that command does.cat -n
just prints all lines in the file, numbering each one. You'll get a list of users that exist on that system, but you won't get much login info.
– cpast
Feb 21 '13 at 5:01
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f13043%2fhow-can-i-find-the-number-of-users-online-in-linux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
13 Answers
13
active
oldest
votes
13 Answers
13
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are looking for the wc
(word count) command.
Try this:
users | wc -w
note that this approach (an who/w solutions) show only users logged in, not necessarily active users (i.e. users that start a process and then logout leaving the running process behind). Just to give a heads up about the difference.
– estani
Mar 18 '13 at 13:45
add a comment |
You are looking for the wc
(word count) command.
Try this:
users | wc -w
note that this approach (an who/w solutions) show only users logged in, not necessarily active users (i.e. users that start a process and then logout leaving the running process behind). Just to give a heads up about the difference.
– estani
Mar 18 '13 at 13:45
add a comment |
You are looking for the wc
(word count) command.
Try this:
users | wc -w
You are looking for the wc
(word count) command.
Try this:
users | wc -w
answered Jul 26 '09 at 3:26
John TJohn T
143k20295331
143k20295331
note that this approach (an who/w solutions) show only users logged in, not necessarily active users (i.e. users that start a process and then logout leaving the running process behind). Just to give a heads up about the difference.
– estani
Mar 18 '13 at 13:45
add a comment |
note that this approach (an who/w solutions) show only users logged in, not necessarily active users (i.e. users that start a process and then logout leaving the running process behind). Just to give a heads up about the difference.
– estani
Mar 18 '13 at 13:45
note that this approach (an who/w solutions) show only users logged in, not necessarily active users (i.e. users that start a process and then logout leaving the running process behind). Just to give a heads up about the difference.
– estani
Mar 18 '13 at 13:45
note that this approach (an who/w solutions) show only users logged in, not necessarily active users (i.e. users that start a process and then logout leaving the running process behind). Just to give a heads up about the difference.
– estani
Mar 18 '13 at 13:45
add a comment |
Classically, the command is 'who' rather than 'users', but 'who' gives you more information. Looking back at the original Unix articles (mid-70s), the example would have been:
who | wc -l
Using 'wc -l' counts lines of output - it works with both 'users' and 'who'. Using '-w' only works reliably when there is one word per user (as with 'users' but not with 'who').
You could use 'grep -c' to count the lines. Since you are only interested in non-blank user names, you could do:
who | grep -c .
There's always at least one character on each line.
As noted in the comments by John T, the users
command differs from who
in a number of respects. The most important one is that instead of giving one name per line, it spreads the names out several per line — I don't have a machine with enough different users logged in to test what happens when the number of users becomes large. The other difference is that 'who' reports on terminal connections in use. With multiple terminal windows open, it will show multiple lines for a single user, whereas 'users' seems to list a logged in user just once.
As a consequence of this difference, the 'grep -c .
' formulation won't work with the 'users' command; 'wc -w
' is necessary.
small nitpick - the users command does not print 1 line per user, it just prints id's sequentially, so grep -c . would not work in this case. Smart thinking though.
– John T
Jul 26 '09 at 3:59
this also means that wc -l will not work with the users command, as shown here: i26.tinypic.com/4pw0vd.png
– John T
Jul 26 '09 at 4:11
@John T: oh - well, given screen shot, you're correct. I tested 'users' on MacOS X - but with just one user logged in. When I double checked with a second user logged in, I see the 'all on one line' behaviour.
– Jonathan Leffler
Jul 26 '09 at 5:52
1
to simulate more users you can SSH into your own box :)
– John T
Jul 26 '09 at 5:59
Thank you for this valuable information, although I wanted to stick with the "users" command. Also upvoted you, thanks.
– Anonymous
Aug 1 '09 at 23:54
add a comment |
Classically, the command is 'who' rather than 'users', but 'who' gives you more information. Looking back at the original Unix articles (mid-70s), the example would have been:
who | wc -l
Using 'wc -l' counts lines of output - it works with both 'users' and 'who'. Using '-w' only works reliably when there is one word per user (as with 'users' but not with 'who').
You could use 'grep -c' to count the lines. Since you are only interested in non-blank user names, you could do:
who | grep -c .
There's always at least one character on each line.
As noted in the comments by John T, the users
command differs from who
in a number of respects. The most important one is that instead of giving one name per line, it spreads the names out several per line — I don't have a machine with enough different users logged in to test what happens when the number of users becomes large. The other difference is that 'who' reports on terminal connections in use. With multiple terminal windows open, it will show multiple lines for a single user, whereas 'users' seems to list a logged in user just once.
As a consequence of this difference, the 'grep -c .
' formulation won't work with the 'users' command; 'wc -w
' is necessary.
small nitpick - the users command does not print 1 line per user, it just prints id's sequentially, so grep -c . would not work in this case. Smart thinking though.
– John T
Jul 26 '09 at 3:59
this also means that wc -l will not work with the users command, as shown here: i26.tinypic.com/4pw0vd.png
– John T
Jul 26 '09 at 4:11
@John T: oh - well, given screen shot, you're correct. I tested 'users' on MacOS X - but with just one user logged in. When I double checked with a second user logged in, I see the 'all on one line' behaviour.
– Jonathan Leffler
Jul 26 '09 at 5:52
1
to simulate more users you can SSH into your own box :)
– John T
Jul 26 '09 at 5:59
Thank you for this valuable information, although I wanted to stick with the "users" command. Also upvoted you, thanks.
– Anonymous
Aug 1 '09 at 23:54
add a comment |
Classically, the command is 'who' rather than 'users', but 'who' gives you more information. Looking back at the original Unix articles (mid-70s), the example would have been:
who | wc -l
Using 'wc -l' counts lines of output - it works with both 'users' and 'who'. Using '-w' only works reliably when there is one word per user (as with 'users' but not with 'who').
You could use 'grep -c' to count the lines. Since you are only interested in non-blank user names, you could do:
who | grep -c .
There's always at least one character on each line.
As noted in the comments by John T, the users
command differs from who
in a number of respects. The most important one is that instead of giving one name per line, it spreads the names out several per line — I don't have a machine with enough different users logged in to test what happens when the number of users becomes large. The other difference is that 'who' reports on terminal connections in use. With multiple terminal windows open, it will show multiple lines for a single user, whereas 'users' seems to list a logged in user just once.
As a consequence of this difference, the 'grep -c .
' formulation won't work with the 'users' command; 'wc -w
' is necessary.
Classically, the command is 'who' rather than 'users', but 'who' gives you more information. Looking back at the original Unix articles (mid-70s), the example would have been:
who | wc -l
Using 'wc -l' counts lines of output - it works with both 'users' and 'who'. Using '-w' only works reliably when there is one word per user (as with 'users' but not with 'who').
You could use 'grep -c' to count the lines. Since you are only interested in non-blank user names, you could do:
who | grep -c .
There's always at least one character on each line.
As noted in the comments by John T, the users
command differs from who
in a number of respects. The most important one is that instead of giving one name per line, it spreads the names out several per line — I don't have a machine with enough different users logged in to test what happens when the number of users becomes large. The other difference is that 'who' reports on terminal connections in use. With multiple terminal windows open, it will show multiple lines for a single user, whereas 'users' seems to list a logged in user just once.
As a consequence of this difference, the 'grep -c .
' formulation won't work with the 'users' command; 'wc -w
' is necessary.
edited Mar 20 '17 at 10:17
Community♦
1
1
answered Jul 26 '09 at 3:53
Jonathan LefflerJonathan Leffler
4,19612336
4,19612336
small nitpick - the users command does not print 1 line per user, it just prints id's sequentially, so grep -c . would not work in this case. Smart thinking though.
– John T
Jul 26 '09 at 3:59
this also means that wc -l will not work with the users command, as shown here: i26.tinypic.com/4pw0vd.png
– John T
Jul 26 '09 at 4:11
@John T: oh - well, given screen shot, you're correct. I tested 'users' on MacOS X - but with just one user logged in. When I double checked with a second user logged in, I see the 'all on one line' behaviour.
– Jonathan Leffler
Jul 26 '09 at 5:52
1
to simulate more users you can SSH into your own box :)
– John T
Jul 26 '09 at 5:59
Thank you for this valuable information, although I wanted to stick with the "users" command. Also upvoted you, thanks.
– Anonymous
Aug 1 '09 at 23:54
add a comment |
small nitpick - the users command does not print 1 line per user, it just prints id's sequentially, so grep -c . would not work in this case. Smart thinking though.
– John T
Jul 26 '09 at 3:59
this also means that wc -l will not work with the users command, as shown here: i26.tinypic.com/4pw0vd.png
– John T
Jul 26 '09 at 4:11
@John T: oh - well, given screen shot, you're correct. I tested 'users' on MacOS X - but with just one user logged in. When I double checked with a second user logged in, I see the 'all on one line' behaviour.
– Jonathan Leffler
Jul 26 '09 at 5:52
1
to simulate more users you can SSH into your own box :)
– John T
Jul 26 '09 at 5:59
Thank you for this valuable information, although I wanted to stick with the "users" command. Also upvoted you, thanks.
– Anonymous
Aug 1 '09 at 23:54
small nitpick - the users command does not print 1 line per user, it just prints id's sequentially, so grep -c . would not work in this case. Smart thinking though.
– John T
Jul 26 '09 at 3:59
small nitpick - the users command does not print 1 line per user, it just prints id's sequentially, so grep -c . would not work in this case. Smart thinking though.
– John T
Jul 26 '09 at 3:59
this also means that wc -l will not work with the users command, as shown here: i26.tinypic.com/4pw0vd.png
– John T
Jul 26 '09 at 4:11
this also means that wc -l will not work with the users command, as shown here: i26.tinypic.com/4pw0vd.png
– John T
Jul 26 '09 at 4:11
@John T: oh - well, given screen shot, you're correct. I tested 'users' on MacOS X - but with just one user logged in. When I double checked with a second user logged in, I see the 'all on one line' behaviour.
– Jonathan Leffler
Jul 26 '09 at 5:52
@John T: oh - well, given screen shot, you're correct. I tested 'users' on MacOS X - but with just one user logged in. When I double checked with a second user logged in, I see the 'all on one line' behaviour.
– Jonathan Leffler
Jul 26 '09 at 5:52
1
1
to simulate more users you can SSH into your own box :)
– John T
Jul 26 '09 at 5:59
to simulate more users you can SSH into your own box :)
– John T
Jul 26 '09 at 5:59
Thank you for this valuable information, although I wanted to stick with the "users" command. Also upvoted you, thanks.
– Anonymous
Aug 1 '09 at 23:54
Thank you for this valuable information, although I wanted to stick with the "users" command. Also upvoted you, thanks.
– Anonymous
Aug 1 '09 at 23:54
add a comment |
Open a shell and type:
who -q
The last line will give you a count.
EDIT:
(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
that counts all logins of the same user in the total.
– hayalci
Jul 26 '09 at 18:56
check the re-edit, I think you'll find that the new answers address that.
– Avery Payne
Jul 27 '09 at 15:33
This still doesn't work, uniq only removes duplicate successive lines, you need to sort the output of who first.
– theotherreceive
Jul 27 '09 at 18:10
that's what I get for posting answers at 1am. (sigh) fixed.
– Avery Payne
Jul 27 '09 at 19:37
add a comment |
Open a shell and type:
who -q
The last line will give you a count.
EDIT:
(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
that counts all logins of the same user in the total.
– hayalci
Jul 26 '09 at 18:56
check the re-edit, I think you'll find that the new answers address that.
– Avery Payne
Jul 27 '09 at 15:33
This still doesn't work, uniq only removes duplicate successive lines, you need to sort the output of who first.
– theotherreceive
Jul 27 '09 at 18:10
that's what I get for posting answers at 1am. (sigh) fixed.
– Avery Payne
Jul 27 '09 at 19:37
add a comment |
Open a shell and type:
who -q
The last line will give you a count.
EDIT:
(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
Open a shell and type:
who -q
The last line will give you a count.
EDIT:
(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
edited Jul 27 '09 at 19:37
answered Jul 26 '09 at 4:27
Avery PayneAvery Payne
2,19611824
2,19611824
that counts all logins of the same user in the total.
– hayalci
Jul 26 '09 at 18:56
check the re-edit, I think you'll find that the new answers address that.
– Avery Payne
Jul 27 '09 at 15:33
This still doesn't work, uniq only removes duplicate successive lines, you need to sort the output of who first.
– theotherreceive
Jul 27 '09 at 18:10
that's what I get for posting answers at 1am. (sigh) fixed.
– Avery Payne
Jul 27 '09 at 19:37
add a comment |
that counts all logins of the same user in the total.
– hayalci
Jul 26 '09 at 18:56
check the re-edit, I think you'll find that the new answers address that.
– Avery Payne
Jul 27 '09 at 15:33
This still doesn't work, uniq only removes duplicate successive lines, you need to sort the output of who first.
– theotherreceive
Jul 27 '09 at 18:10
that's what I get for posting answers at 1am. (sigh) fixed.
– Avery Payne
Jul 27 '09 at 19:37
that counts all logins of the same user in the total.
– hayalci
Jul 26 '09 at 18:56
that counts all logins of the same user in the total.
– hayalci
Jul 26 '09 at 18:56
check the re-edit, I think you'll find that the new answers address that.
– Avery Payne
Jul 27 '09 at 15:33
check the re-edit, I think you'll find that the new answers address that.
– Avery Payne
Jul 27 '09 at 15:33
This still doesn't work, uniq only removes duplicate successive lines, you need to sort the output of who first.
– theotherreceive
Jul 27 '09 at 18:10
This still doesn't work, uniq only removes duplicate successive lines, you need to sort the output of who first.
– theotherreceive
Jul 27 '09 at 18:10
that's what I get for posting answers at 1am. (sigh) fixed.
– Avery Payne
Jul 27 '09 at 19:37
that's what I get for posting answers at 1am. (sigh) fixed.
– Avery Payne
Jul 27 '09 at 19:37
add a comment |
Do you want to see the number of sessions, or the number of actual users?
$ who
andrew tty1 2009-07-26 15:31 (:0)
andrew pts/0 2009-07-27 00:11 (:0.0)
andrew pts/1 2009-07-27 01:58 (:0.0)
That's on my laptop, so i'm the only user, but i'm logged on three times.
$ who | wc -l
3
$ users | wc -w
3
It is fairly easy to filter out these duplicates though to get the number of actual users.
$ users | tr ' ' 'n' | sort -u
andrew
$ users | tr ' ' 'n' | sort -u | wc -l
1
add a comment |
Do you want to see the number of sessions, or the number of actual users?
$ who
andrew tty1 2009-07-26 15:31 (:0)
andrew pts/0 2009-07-27 00:11 (:0.0)
andrew pts/1 2009-07-27 01:58 (:0.0)
That's on my laptop, so i'm the only user, but i'm logged on three times.
$ who | wc -l
3
$ users | wc -w
3
It is fairly easy to filter out these duplicates though to get the number of actual users.
$ users | tr ' ' 'n' | sort -u
andrew
$ users | tr ' ' 'n' | sort -u | wc -l
1
add a comment |
Do you want to see the number of sessions, or the number of actual users?
$ who
andrew tty1 2009-07-26 15:31 (:0)
andrew pts/0 2009-07-27 00:11 (:0.0)
andrew pts/1 2009-07-27 01:58 (:0.0)
That's on my laptop, so i'm the only user, but i'm logged on three times.
$ who | wc -l
3
$ users | wc -w
3
It is fairly easy to filter out these duplicates though to get the number of actual users.
$ users | tr ' ' 'n' | sort -u
andrew
$ users | tr ' ' 'n' | sort -u | wc -l
1
Do you want to see the number of sessions, or the number of actual users?
$ who
andrew tty1 2009-07-26 15:31 (:0)
andrew pts/0 2009-07-27 00:11 (:0.0)
andrew pts/1 2009-07-27 01:58 (:0.0)
That's on my laptop, so i'm the only user, but i'm logged on three times.
$ who | wc -l
3
$ users | wc -w
3
It is fairly easy to filter out these duplicates though to get the number of actual users.
$ users | tr ' ' 'n' | sort -u
andrew
$ users | tr ' ' 'n' | sort -u | wc -l
1
answered Jul 27 '09 at 1:32
theotherreceivetheotherreceive
753611
753611
add a comment |
add a comment |
Here's a bash version of tink's great awk post:
set $(users)
declare -A user
for u ; do ((user[$u]++)) ; done
for key in "${!user[@]}" ; do echo "$key: ${user[$key]}" ; done | column -t | sort -nk 2
Ok, it's a little bit longer, but was worth finding this one ... :).
While testing, do before next attempt:
shift $# # clear positional parameters
unset user # remove associative array variable
add a comment |
Here's a bash version of tink's great awk post:
set $(users)
declare -A user
for u ; do ((user[$u]++)) ; done
for key in "${!user[@]}" ; do echo "$key: ${user[$key]}" ; done | column -t | sort -nk 2
Ok, it's a little bit longer, but was worth finding this one ... :).
While testing, do before next attempt:
shift $# # clear positional parameters
unset user # remove associative array variable
add a comment |
Here's a bash version of tink's great awk post:
set $(users)
declare -A user
for u ; do ((user[$u]++)) ; done
for key in "${!user[@]}" ; do echo "$key: ${user[$key]}" ; done | column -t | sort -nk 2
Ok, it's a little bit longer, but was worth finding this one ... :).
While testing, do before next attempt:
shift $# # clear positional parameters
unset user # remove associative array variable
Here's a bash version of tink's great awk post:
set $(users)
declare -A user
for u ; do ((user[$u]++)) ; done
for key in "${!user[@]}" ; do echo "$key: ${user[$key]}" ; done | column -t | sort -nk 2
Ok, it's a little bit longer, but was worth finding this one ... :).
While testing, do before next attempt:
shift $# # clear positional parameters
unset user # remove associative array variable
edited Jun 10 '16 at 10:35
answered Jun 9 '16 at 13:19
SaschSasch
313
313
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Jan 23 '12 at 19:58
CrisCris
211
211
add a comment |
add a comment |
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 :)
add a comment |
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 :)
add a comment |
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 :)
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 :)
answered Jul 26 '09 at 20:36
KimKim
2,01021426
2,01021426
add a comment |
add a comment |
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.
w:
v
22:40:38 up 3 days, 22 min, 1 user, load average: 0.02, 0.01, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
manuel pts/0 pc-manuel 09:35 0.00s 0.07s 0.00s /usr/bin/screen -xRR
uptime:
v
22:39:18 up 3 days, 21 min, 1 user, load average: 0.08, 0.02, 0.01
add a comment |
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.
w:
v
22:40:38 up 3 days, 22 min, 1 user, load average: 0.02, 0.01, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
manuel pts/0 pc-manuel 09:35 0.00s 0.07s 0.00s /usr/bin/screen -xRR
uptime:
v
22:39:18 up 3 days, 21 min, 1 user, load average: 0.08, 0.02, 0.01
add a comment |
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.
w:
v
22:40:38 up 3 days, 22 min, 1 user, load average: 0.02, 0.01, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
manuel pts/0 pc-manuel 09:35 0.00s 0.07s 0.00s /usr/bin/screen -xRR
uptime:
v
22:39:18 up 3 days, 21 min, 1 user, load average: 0.08, 0.02, 0.01
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.
w:
v
22:40:38 up 3 days, 22 min, 1 user, load average: 0.02, 0.01, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
manuel pts/0 pc-manuel 09:35 0.00s 0.07s 0.00s /usr/bin/screen -xRR
uptime:
v
22:39:18 up 3 days, 21 min, 1 user, load average: 0.08, 0.02, 0.01
answered Jul 26 '09 at 20:42
Manuel FauxManuel Faux
6611611
6611611
add a comment |
add a comment |
And a method that uses only one pipe...
users | awk '{for(i=1;i<=NF;i++){a[$i]++}}END{for(i in a){print i"t"a[i]}}'
:}
add a comment |
And a method that uses only one pipe...
users | awk '{for(i=1;i<=NF;i++){a[$i]++}}END{for(i in a){print i"t"a[i]}}'
:}
add a comment |
And a method that uses only one pipe...
users | awk '{for(i=1;i<=NF;i++){a[$i]++}}END{for(i in a){print i"t"a[i]}}'
:}
And a method that uses only one pipe...
users | awk '{for(i=1;i<=NF;i++){a[$i]++}}END{for(i in a){print i"t"a[i]}}'
:}
answered Feb 17 '13 at 19:20
tinktink
1,3271914
1,3271914
add a comment |
add a comment |
http://www.gnu.org/software/coreutils/manual/html_node/who-invocation.html
"who" prints information about users who are currently logged on. Synopsis:
who [option] [file] [am i]
add a comment |
http://www.gnu.org/software/coreutils/manual/html_node/who-invocation.html
"who" prints information about users who are currently logged on. Synopsis:
who [option] [file] [am i]
add a comment |
http://www.gnu.org/software/coreutils/manual/html_node/who-invocation.html
"who" prints information about users who are currently logged on. Synopsis:
who [option] [file] [am i]
http://www.gnu.org/software/coreutils/manual/html_node/who-invocation.html
"who" prints information about users who are currently logged on. Synopsis:
who [option] [file] [am i]
answered Jan 29 '15 at 6:22
TonyTony
1111
1111
add a comment |
add a comment |
You could always download the free tool for unix called TOP. It produces a list of the users and also what they are doing on the system at the time and will continue to update as long as it is running.
It is located at http://www.unixtop.org/
It has many command line switches so you should be able to extract the information you are looking for.
I've yet to find a linux distro that doesn't include top by default, let alone not have an option to install it from packages.
– theotherreceive
Jul 27 '09 at 1:32
add a comment |
You could always download the free tool for unix called TOP. It produces a list of the users and also what they are doing on the system at the time and will continue to update as long as it is running.
It is located at http://www.unixtop.org/
It has many command line switches so you should be able to extract the information you are looking for.
I've yet to find a linux distro that doesn't include top by default, let alone not have an option to install it from packages.
– theotherreceive
Jul 27 '09 at 1:32
add a comment |
You could always download the free tool for unix called TOP. It produces a list of the users and also what they are doing on the system at the time and will continue to update as long as it is running.
It is located at http://www.unixtop.org/
It has many command line switches so you should be able to extract the information you are looking for.
You could always download the free tool for unix called TOP. It produces a list of the users and also what they are doing on the system at the time and will continue to update as long as it is running.
It is located at http://www.unixtop.org/
It has many command line switches so you should be able to extract the information you are looking for.
answered Jul 26 '09 at 4:17
AxxmasterrAxxmasterr
6,80363557
6,80363557
I've yet to find a linux distro that doesn't include top by default, let alone not have an option to install it from packages.
– theotherreceive
Jul 27 '09 at 1:32
add a comment |
I've yet to find a linux distro that doesn't include top by default, let alone not have an option to install it from packages.
– theotherreceive
Jul 27 '09 at 1:32
I've yet to find a linux distro that doesn't include top by default, let alone not have an option to install it from packages.
– theotherreceive
Jul 27 '09 at 1:32
I've yet to find a linux distro that doesn't include top by default, let alone not have an option to install it from packages.
– theotherreceive
Jul 27 '09 at 1:32
add a comment |
who | cut -d ' ' -f1 | uniq | wc -l
2
This seems like a minor variation of Kim's answer, and it contains no explanation. It might be more appropriate as a comment on that answer (which requires a little more rep). The intention is that each answer provide a solution that is substantively different from what has already been contributed.
– fixer1234
Feb 1 at 7:20
add a comment |
who | cut -d ' ' -f1 | uniq | wc -l
2
This seems like a minor variation of Kim's answer, and it contains no explanation. It might be more appropriate as a comment on that answer (which requires a little more rep). The intention is that each answer provide a solution that is substantively different from what has already been contributed.
– fixer1234
Feb 1 at 7:20
add a comment |
who | cut -d ' ' -f1 | uniq | wc -l
who | cut -d ' ' -f1 | uniq | wc -l
edited Feb 1 at 8:41
Mureinik
2,86171725
2,86171725
answered Feb 1 at 5:14
Arjun DandagiArjun Dandagi
11
11
2
This seems like a minor variation of Kim's answer, and it contains no explanation. It might be more appropriate as a comment on that answer (which requires a little more rep). The intention is that each answer provide a solution that is substantively different from what has already been contributed.
– fixer1234
Feb 1 at 7:20
add a comment |
2
This seems like a minor variation of Kim's answer, and it contains no explanation. It might be more appropriate as a comment on that answer (which requires a little more rep). The intention is that each answer provide a solution that is substantively different from what has already been contributed.
– fixer1234
Feb 1 at 7:20
2
2
This seems like a minor variation of Kim's answer, and it contains no explanation. It might be more appropriate as a comment on that answer (which requires a little more rep). The intention is that each answer provide a solution that is substantively different from what has already been contributed.
– fixer1234
Feb 1 at 7:20
This seems like a minor variation of Kim's answer, and it contains no explanation. It might be more appropriate as a comment on that answer (which requires a little more rep). The intention is that each answer provide a solution that is substantively different from what has already been contributed.
– fixer1234
Feb 1 at 7:20
add a comment |
If you are looking for the total number of users logged in and logged off in a proper sequence, the best command to run is
cat -n /etc/passwd
2
No, that's not what that command does.cat -n
just prints all lines in the file, numbering each one. You'll get a list of users that exist on that system, but you won't get much login info.
– cpast
Feb 21 '13 at 5:01
add a comment |
If you are looking for the total number of users logged in and logged off in a proper sequence, the best command to run is
cat -n /etc/passwd
2
No, that's not what that command does.cat -n
just prints all lines in the file, numbering each one. You'll get a list of users that exist on that system, but you won't get much login info.
– cpast
Feb 21 '13 at 5:01
add a comment |
If you are looking for the total number of users logged in and logged off in a proper sequence, the best command to run is
cat -n /etc/passwd
If you are looking for the total number of users logged in and logged off in a proper sequence, the best command to run is
cat -n /etc/passwd
edited Feb 21 '13 at 6:29
cpast
2,11421426
2,11421426
answered Feb 21 '13 at 4:34
Amrik SinghAmrik Singh
7
7
2
No, that's not what that command does.cat -n
just prints all lines in the file, numbering each one. You'll get a list of users that exist on that system, but you won't get much login info.
– cpast
Feb 21 '13 at 5:01
add a comment |
2
No, that's not what that command does.cat -n
just prints all lines in the file, numbering each one. You'll get a list of users that exist on that system, but you won't get much login info.
– cpast
Feb 21 '13 at 5:01
2
2
No, that's not what that command does.
cat -n
just prints all lines in the file, numbering each one. You'll get a list of users that exist on that system, but you won't get much login info.– cpast
Feb 21 '13 at 5:01
No, that's not what that command does.
cat -n
just prints all lines in the file, numbering each one. You'll get a list of users that exist on that system, but you won't get much login info.– cpast
Feb 21 '13 at 5:01
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f13043%2fhow-can-i-find-the-number-of-users-online-in-linux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown