Linux / Unix: users Command Examples

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
CategoryN/A
DifficultyEasy
Root privilegesNo
Est. reading time1m
Table of 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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum