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. Let us see some users command examples using the terminal applications.

users command details
DescriptionList users currently logged in
CategoryUser Information
Difficulty levelEasy
Root privilegesNo
OS compatibilityBSD Linux macOS Unix WSL
Est. reading time2 minutes
Advertisement

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

understadning users command line options

Want to display help and exit to the command prompt? Try passing the --help when using the GNU/Linux:
users --help
Similarly, you can output version information and exit to shell prompt. Pass the --version option as follows:
users --version

Summing up

You learned about the users command that lists the login names of the users currently on the Linux or Unix system.

See also

  • /var/run/utmp file – The utmp file allows one to discover information about who is currently using the system. There may be more users currently using the system, because not all programs use utmp logging
  • /var/log/wtmp file.
  • Consult the following man pages using the man command or help command at the shell prompt:
    man users

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

0 comments… add one

Leave a Reply

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

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.