RSS Feed

Find the total amount of logged in users in Linux

Finding out how many users are logged into a box is surprisingly an easy task. You can use who to list all ttys connections like so:

srcnix console Nov 2 09:23
srcnix ttys000 Nov 5 09:42
srcnix ttys001 Nov 3 15:08
srcnix ttys002 Nov 3 15:28
srcnix ttys003 Nov 4 10:28
srcnix ttys004 Nov 3 09:59
srcnix ttys005 Nov 3 09:59

Of course, for us lazy people who want to know how many people are currently logged in you can pipe the result of who through word count.

who | wc -l

This saves you having to count and is often useful when writing scripts. Word count (wc) counts words, lines, characters and bytes. The -l parameter signifies to count the lines and as who lists all sessions line by line this is exactly what we need.

Posted in Linux on the 6th November 2010


Your email address will not be published. Required fields are marked *