users command in Linux with Examples

users command in Linux Provides the names of users who are currently logged in.

The users command in Linux is used to display a list of currently logged-in users on the system. It reads the /var/run/utmp file to gather this information. Here are a few examples of how to use the users command:

users command in Linux with Examples

On the man page, describes it

  • users – print the user names of users currently logged in to the current host.
  • man users – More details information.

users command in Linux with Examples

$ users

Count the number of logged-in users:

users | wc -w

By piping the output of the users command to wc -w, we can count the number of words in the output, which corresponds to the number of logged-in users.

Check if a specific user is logged in:

users | grep <username>

Check if a user is logged in and display a custom message:

if users | grep -q <username>; then echo "<username> is logged in"; else echo "<username> is not logged in"; fi

Conclusion

users command is a simple command in Linux. It is the most popular in-use terminal Linux prints the user names of users currently logged in to the current host. These are a few examples of how to use the users command in Linux. The command is simple and primarily used to retrieve information about currently logged-in users. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.