Linux / Unix: users Command Examples

by on January 27, 2013 · 0 comments· LAST UPDATED January 27, 2014

in , ,

users command

I am a new Linux and Unix system user. How do I list current users on Linux or Unix-like operating system using shell prompt?

You need to use users command to display the login names of the users currently on the server, in sorted order, on a single line.

users command details
DescriptionList users currently logged in
Category
Difficulty
Root privilegesNo
Estimated completion time1m
Contents

Purpose

Display login names of users currently logged in on system

Syntax

The basic syntax is as follows:

users
users [fileNameHere]
users --help
users --version

users command examples

To display list of user names of users currently logged in to the current server or workstation, type:
$ groups
Sample outputs:

Animated gif 01: users command in action

Animated gif 01: users command in action

In this example, three users are output: nixcraft, root, and vivek. You can easily count total users logged in with the following wc command:
$ users | wc -w
Sample outputs:

      3

You can list all users in the system using /etc/passwd file
$ cat /etc/passwd
OR use awk command as follows:
$ awk -F':' '{ print $1}' /etc/passwd
Sample outputs:

root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
proxy
www-data
backup
list
irc
gnats
nobody
libuuid
Debian-exim
statd
sshd
vivek
messagebus
bind
nixcraft
dnsmasq
See also
CategoryList of Unix and Linux commands
File Managementcat
Network Utilitiesdighostip
Processes Managementbgchrootdisownfgjobskillkillallpwdxtimepidofpstree
Searchingwhereiswhich
User Informationgroupsidlastlastcommlognameuserswwhowhoamilidmembers

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 0 comments… add one now }

Leave a Comment

Tagged as: , , , , ,

Previous Faq:

Next Faq: