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
Estimated completion time1m
Contents
[/donotprint]

ADVERTISEMENTS

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

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig 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 VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.