Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Linux

How to List Users in Linux: A Step-by-Step Guide

by Hollie Moore
4 months ago
in Linux
List Users In Linux
ShareTweetSendShare
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

Learn how to list users in Linux and effectively manage user accounts with our comprehensive article. Explore step-by-step instructions and essential commands to simplify user management in Linux. Unlock the power of Linux user administration and optimize your system's security with our expert guidance.

ADVERTISEMENT

One of the core components of Linux system administration is managing users. Knowing how to list users in Linux is crucial whether you’re an experienced sysadmin or a curious Linux viewer exploring the command line. We’ll provide you a step-by-step tutorial on how to list users in Linux using several techniques in this article.

Table of Contents

  1. Prerequisites
  2. List Users in Linux
  3. cat Command
  4. List Users Using – less Command
  5. cut Command
  6. awk Command
  7. getent Command
  8. compgen Command
  9. Conclusion

Prerequisites

  • Linux-powered hardware.
  • access to the command line or terminal.

List Users in Linux

Linux information can be stores the local users in the /etc/passwd file. Each line having a file contains content about a single user, including their username, user ID number (UID), home directory, and the login shell.

The following commands are used in the tutorial:

ADVERTISEMENT
  • cat command
  • less command
  • cut command
  • awk command
  • getent command

cat Command

When using the “cat” command with the "/etc/passwd" file, you can view the user account information stored within. Each line in the file represents a user, and the first field on each line is the username. You can acquire a detailed list of users configured on your Linux system by showing the contents of this file.

You might also like

Symbolic Links In Linux

Symbolic Links in Linux: What They Are and How to Use Them

2 months ago
Ubuntu Password

Reset your Forgotten Ubuntu Password in 2 Minutes

2 months ago
cat /etc/passwd

less Command

When dealing with systems that have a large number of users, it can be beneficial to limit the output displayed from the "/etc/passwd" file at once. To accomplish this, use a terminal pager command such as “less” or “more” to go through the file’s content in a controlled manner, either line by line or page by page.

By utilizing these pager commands, you can conveniently navigate through the extensive user account information stored in the "/etc/passwd" file, enhancing readability and ease of use.

ADVERTISEMENT
less /etc/passwd

Use more to achieve the same result. This is an older command with a more limited set of capabilities:

more /etc/passwd

cut Command

We can accomplish the same thing with the cut command. We must use the -d (delimiter) option and instruct it to choose only the first field using the -f (fields) option.

ADVERTISEMENT
cut -d: -f1 /etc/passwd

Note: The "/etc/shadow" file contains encrypted passwords and requires administrative privileges to access. Hence, the use of “sudo” is required.

This command uses the “cut” command to extract the first field (username) from the "/etc/shadow" file, which contains password information.

ADVERTISEMENT
sudo cut -d: -f1 /etc/shadow

awk Command

We may display only the username using the awk command. This is useful when building a script that wants to perform anything with a large number of user accounts. Listing the account user names and redirecting them to a text file can save you a lot of time. The rest of the command can then be copied and pasted onto each line.

We will instruct awk to use the colon “:” as a field separator and to print the first field. The -F (field separator) option will be used.

ADVERTISEMENT
awk -F: '{ print $1 }' /etc/passwd

getent Command

The “getent” command is used to access and get information from system databases. To consider a list of files in the "/etc/passwd" file, we can use the “getent” command with “passwd” parameter. These instructions are the command to specifically retrieve and display the user account entries stored in the "/etc/passwd" file.

You can view the whole list of users configured on your Linux system by using this command.

getent passwd

compgen Command

To list the user accounts, use the compgen command with the -u (user) option. Instead of one long list with a single user name per line, we’ll pipe the output through the column command to list the user accounts in columns.

compgen -u | column

Also read: SCP Command in Linux: A Beginner’s Guide to Secure File Transfers

Conclusion

Listing users in Linux is an essential operation for both system administrators and users. This article has shown you five ways to complete this operation using commands like as “cut,” “cat,” “getent,” and “awk.” You may rapidly obtain a list of users on your Linux system using these ways, allowing you to manage and maintain user accounts effectively. Please feel free to share your thoughts and feedback in the comment section below.

Tags: CentOSDebianUbuntu
Share1Tweet1SendShare
Hollie Moore

Hollie Moore

Greetings, I am a technical writer who specializes in conveying complex topics in simple and engaging ways. I have a degree in computer science and journalism, and I have experience writing about software, data, and design. My content includes blog posts, tutorials, and documentation pages, which I always strive to make clear, concise, and useful for the reader. I am constantly learning new things and sharing my insights with others.

Leave a Reply Cancel reply

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

Related Posts

&Quot; Systemd Service On Linux

How to Create a New systemd Service on Linux: A Step-by-Step Guide

3 months ago
List Groups In Linux

How to List Groups in Linux: A Guide for Beginners

3 months ago
Hostname In Linux

How to Modify the Hostname in Linux

3 months ago
Linux Systems

Linux systems Hacked with OpenSSH Malware

3 months ago

Follow Us

Trending Articles

Microsoft Editor Vs Grammarly

Microsoft Editor vs Grammarly: Which is the Best Grammar Checker?

September 18, 2023

7 Best AI Girl Generators for Creating Realistic and Beautiful AI Girls

10 Best AI Song Generator in 2023 (Free and Paid)

5 Free AI Soulmate Maker: Create Your Perfect Match

WhatsApp Business Gets New Features to Help your Businesses Grow

How to Use ChatGPT to Translate Your Website or Blog

Popular Articles

Remodeled Ai

Remodeled AI: How to Transform Your Home with AI Interior Design

August 25, 2023

7 Best AI Album Cover Generators to Create Stunning Artwork

10 NFT Art Generator: Create and Sell Your Own NFT Artwork

How to Install Waifu Diffusion – Step-by-Step Guide

AI Annotation Jobs: Everything You Need to Know

How to Find Who Unfollowed You on Instagram

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Cloudbooklet Logo

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Applications
  • Linux

Cloudbooklet © 2023 All rights reserved.