Linux / Unix: users Command Examples

last updated in Categories , ,
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.[donotprint]

users command details
DescriptionList users currently logged in
Category
Difficulty
Root privilegesNo
Estimated completion time1m
Contents
[/donotprint]

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
  • /var/run/utmp file.
  • /var/log/wtmp file.
  • users(1) Linux/Unix command man page
CategoryList of Unix and Linux commands
File Managementcat
Network Utilitiesdighostip
Package Managerapkapt
Processes Managementbgchrootdisownfgjobskillkillallpwdxtimepidofpstree
Searchingwhereiswhich
User Informationidgroupslastlastcommlognameuserswwhowhoamilid/libuser-lidmembers

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.