{"id":15281,"date":"2023-08-03T06:18:08","date_gmt":"2023-08-03T06:18:08","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=15281"},"modified":"2023-12-31T06:32:18","modified_gmt":"2023-12-31T06:32:18","slug":"bash-list-users","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/","title":{"rendered":"How to List Users in Bash [2 Easy Ways]"},"content":{"rendered":"<p style=\"text-align: justify;\">To list users in Bash utilize the <strong>\/etc\/passwd<\/strong> file. This file contains a lot of information about the users. You can find a list of normal users, system users, user\u2019s recent activity and many more by searching over the file. To extract information from \/etc\/passwd file you can use the <strong>read<\/strong> or <strong>getent<\/strong> command. The getent command has a leverage for this purpose as it is far more useful than listing the users only. The theme of this article is to list users in Bash and determine what kind of users they are by reading and extracting info from the <strong>passwd<\/strong> file.<\/p>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/Practice-Files_bash-list-users.zip\" class=\"su-button su-button-style-default\" style=\"color:#000000;background-color:#E8F9FF;border-color:#bac8cc;border-radius:56px\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color:#000000;padding:8px 26px;font-size:20px;line-height:30px;border-color:#effbff;border-radius:56px;text-shadow:0px 0px 0px #000000\"><i class=\"sui sui-download\" style=\"font-size:20px;color:#1AA1D6\"><\/i> Practice Files to List Users in Bash<\/span><\/a><\/div>\n<p style=\"text-align: justify;\"><div class=\"su-youtube su-u-responsive-media-yes\"><iframe width=\"600\" height=\"400\" src=\"https:\/\/www.youtube.com\/embed\/VOBu4X6WGXo?\" frameborder=\"0\" allowfullscreen allow=\"autoplay; encrypted-media; picture-in-picture\" title=\"\"><\/iframe><\/div>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#System_User_and_General_User\" >System User and General User<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#2_Ways_of_Getting_a_List_of_Users_in_Bash\" >2 Ways of Getting a List of Users in Bash<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#Method_01_How_to_Get_a_List_of_Users_by_Reading_the_%E2%80%9Cpasswd%E2%80%9D_File\" >Method 01: How to Get a List of Users by Reading the &#8220;passwd&#8221; File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#Method_02_Printing_User_List_Using_the_%E2%80%9Cgetent%E2%80%9D_Command\" >Method 02: Printing User List Using the &#8220;getent&#8221; Command<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#Comparative_Analysis_of_Methods_of_Listing_Users_in_Bash\" >Comparative Analysis of Methods of Listing Users in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#Each_Field_of_passwd_File\" >Each Field of passwd File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#Counting_System_and_General_User\" >Counting System and General User<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#Checking_the_Existence_of_a_User\" >Checking the Existence of a User<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#People_Also_Ask\" >People Also Ask<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#What_does_users_command_do_in_Linux\" >What does users command do in Linux?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#What_is_the_fourth_field_of_the_etcpasswd_file\" >What is the fourth field of the \/etc\/passwd file?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#How_to_I_list_users_of_a_specific_group_in_Linux\" >How to I list users of a specific group in Linux?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#How_can_I_switch_user_in_Linux\" >How can I switch user in Linux?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"System_User_and_General_User\"><\/span>System User and General User<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li style=\"text-align: justify;\"><strong style=\"font-size: inherit; text-align: justify;\">System users<\/strong><span style=\"font-size: inherit; text-align: justify;\"> are known as <\/span><strong style=\"font-size: inherit; text-align: justify;\">privileged users<\/strong><span style=\"font-size: inherit; text-align: justify;\">. These are accounts on the system with elevated privileges. These users have more extensive control over the system and can perform tasks that regular users cannot. They have access to critical system files, configuration settings, and administrative tools. In Unix-based systems like Linux, the <\/span><strong style=\"font-size: inherit; text-align: justify;\">root<\/strong><span style=\"font-size: inherit; text-align: justify;\"> user is the superuser with complete control over the system<\/span><\/li>\n<li style=\"text-align: justify;\">A <strong>general user<\/strong> is referred to as a <strong>regular user. <\/strong>General users do not have administrative privileges like the <strong>root <\/strong>user of the <strong>Unix<\/strong> system. General users can perform activities, such as running applications, accessing personal files, and using the system&#8217;s basic features.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"2_Ways_of_Getting_a_List_of_Users_in_Bash\"><\/span>2 Ways of Getting a List of Users in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">You can <strong>read<\/strong> the <strong>\/etc\/passwd<\/strong> file or can directly use the <a href=\"https:\/\/linuxsimply.com\/getent-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>getent command<\/strong><\/a> to retrieve information about users. Read the methods below to know more about these.<\/p>\n<div class=\"su-note\"  style=\"border-color:#e5e3d9;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#FFFDF3;border-color:#ffffff;color:#333333;\">\n<p style=\"text-align: justify;\">You can read the <a href=\"#comparative_analysis\"><strong>Comparative Analysis of Methods <\/strong><\/a>to find one that suits you.<\/div><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Method_01_How_to_Get_a_List_of_Users_by_Reading_the_%E2%80%9Cpasswd%E2%80%9D_File\"><\/span>Method 01: How to Get a List of Users by Reading the &#8220;passwd&#8221; File<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The <strong>passwd<\/strong> file is located in the <strong>etc <\/strong>folder of the system. This file contains information on users along with their names. The following script is designed to display information about current system users.<\/p>\n<p>To get a list of users by reading the passed file, use the following script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nwhile IFS=: read -r username _ _ _ _ _ _\ndo\necho &quot;$username&quot;\ndone &lt; \/etc\/passwd<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">The provided Bash script uses a <strong>while loop <\/strong>to read each line of the <strong>\/etc\/passwd <\/strong>file. The I<strong>FS=: <\/strong>sets the <strong>Internal Field Separator <\/strong>to a colon (<strong>:<\/strong>), indicating that each field in the line should be separated by colons. The <strong>read -r username _ _ _ _ _ _<\/strong> command reads the <strong>first field<\/strong> from each line and ignores the rest of the fields. Inside the loop, the script prints the value of the username variable using the <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/output\/echo-command\/\" target=\"_blank\" rel=\"noopener\"><strong>echo command<\/strong><\/a>, displaying one username per line. The input redirection <strong>&lt; \/etc\/passwd<\/strong> ensures that the loop reads the <strong>\/etc\/passwd<\/strong> file as its input.<\/div><\/div>\n<p style=\"text-align: justify;\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-15291\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/3.-Executing-the-script-to-list-users-in-Bash.png\" alt=\"Executing the script to list users in Bash\" width=\"503\" height=\"598\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/3.-Executing-the-script-to-list-users-in-Bash.png 503w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/3.-Executing-the-script-to-list-users-in-Bash-252x300.png 252w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/3.-Executing-the-script-to-list-users-in-Bash-768x913.png 768w\" sizes=\"(max-width: 503px) 100vw, 503px\" \/>Once executed the script will print a whole list of users of the system. If you go down you can also see the currently logged-in username.<img decoding=\"async\" class=\"aligncenter size-full wp-image-15292\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/4.-Finding-currently-logged-in-user-from-the-list.png\" alt=\"Finding currently logged-in user from the list\" width=\"474\" height=\"419\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/4.-Finding-currently-logged-in-user-from-the-list.png 474w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/4.-Finding-currently-logged-in-user-from-the-list-300x265.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/4.-Finding-currently-logged-in-user-from-the-list-767x678.png 767w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/> As you can see the currently logged-in username of my system is printed at the end of the list.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Method_02_Printing_User_List_Using_the_%E2%80%9Cgetent%E2%80%9D_Command\"><\/span>Method 02: Printing User List Using the &#8220;getent&#8221; Command<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The <strong>getent <\/strong>command is another built-in command to get the list of users in the system. Here I am providing a <strong>Bash<\/strong> script to print all the users of the system.<\/p>\n<p style=\"text-align: justify;\">To print the user list using the getent command, go through the below script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Retrieve the list of users using getent command and store it in a variable\nuser_list=$(getent passwd | cut -d: -f1)\n# Print the list of users\necho &quot;List of users:&quot;\necho &quot;$user_list&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">The given Bash script uses the <strong>getent<\/strong> command to retrieve user information and then pipes the output to the <a href=\"https:\/\/linuxsimply.com\/cut-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>cut command<\/strong><\/a>, which extracts only the usernames from each line. The list of usernames is stored in the <strong>user_list<\/strong> variable. Finally, the script prints the list of usernames with using the <strong>echo <\/strong>command.<\/div><\/div>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-15293\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/5.-getent-command-to-list-users-in-Bash.png\" alt=\"getent command to list users in Bash\" width=\"538\" height=\"553\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/5.-getent-command-to-list-users-in-Bash.png 538w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/5.-getent-command-to-list-users-in-Bash-292x300.png 292w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/5.-getent-command-to-list-users-in-Bash-768x789.png 768w\" sizes=\"(max-width: 538px) 100vw, 538px\" \/>Once executed the script will print all the users including <strong>system users<\/strong> and <strong>general users <\/strong>as you can the above image.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Comparative_Analysis_of_Methods_of_Listing_Users_in_Bash\"><\/span><a id=\"comparative_analysis\"><\/a>Comparative Analysis of Methods of Listing Users in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Here is a comparative analysis between the above-discussed methods. Take a look at the analysis to determine which method suits your needs:<\/p>\n<div class=\"su-table su-table-responsive su-table-alternate su-table-fixed\">\n<table style=\"width: 100%\" width=\"100%\">\n<tbody>\n<tr>\n<th style=\"width: 33.1002%\" width=\"208\"><strong>Method<\/strong><\/th>\n<th style=\"width: 33.1002%\" width=\"208\"><strong>Advantage<\/strong><\/th>\n<th style=\"width: 33.1002%\" width=\"208\"><strong>Disadvantage<\/strong><\/th>\n<\/tr>\n<tr>\n<td style=\"width: 33.1002%;text-align: center;vertical-align: middle\" width=\"208\"><strong>\/etc\/passwd<\/strong> file<\/td>\n<td style=\"width: 33.1002%\" width=\"208\">\n<ul>\n<li>Can read all the fields of the passwd file<\/li>\n<\/ul>\n<\/td>\n<td style=\"width: 33.1002%\" width=\"208\">\n<ul>\n<li>Not versatile like the <strong>getent<\/strong> command.<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.1002%;text-align: center;vertical-align: middle\" width=\"208\"><strong>getent<\/strong> command<\/td>\n<td style=\"width: 33.1002%\" width=\"208\">\n<ul>\n<li>Can work on various databases.<\/li>\n<\/ul>\n<\/td>\n<td style=\"width: 33.1002%\" width=\"208\">\n<ul>\n<li>May need to install it in the system<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"text-align: justify\"><span style=\"font-weight: 400\"><\/div>\nI think the best approach here is to use the <strong>getent<\/strong> command as it can extract more information about the user other than the <strong>username<\/strong> only. Moreover, the <strong>getent<\/strong> is straightforward and doesn&#8217;t need to extract any field.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Each_Field_of_passwd_File\"><\/span>Each Field of passwd File<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Let\u2019s talk more about the entire <strong>passwd<\/strong> file instead of just the first field of each line only. Each line of the <strong>passwd <\/strong>file has seven different fields separated by a colon. For example, consider one of the outputs of the <strong>getent<\/strong> <strong>passwd<\/strong> command:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15294\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/6.-Meaning-of-each-field-of-passwd-file-Copy.png\" alt=\" Meaning of each field of passwd file - Copy\" width=\"825\" height=\"378\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/6.-Meaning-of-each-field-of-passwd-file-Copy.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/6.-Meaning-of-each-field-of-passwd-file-Copy-300x137.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/6.-Meaning-of-each-field-of-passwd-file-Copy-766x351.png 766w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p><strong>man<\/strong> \u2013 The <strong>user<\/strong> name or <strong>login<\/strong> name.<\/p>\n<ul>\n<li style=\"text-align: justify;\"><strong>x<\/strong> \u2013 The second field is the password field, which typically contains an <strong>x<\/strong>\u00a0to indicate that the encrypted password is stored in the <strong>\/etc\/shadow<\/strong> file. The actual password hash is stored in the shadow file, which is more secure and accessible only to privileged users. If this field is empty it means the user or application is not password protected.<\/li>\n<li style=\"text-align: justify;\"><strong>6<\/strong> \u2013 This represents the user&#8217;s <strong>unique numerical identifier <\/strong>(<strong>UID<\/strong>). Each user on the system has a unique <strong>UID<\/strong>, which helps the system identify and manage users. Typically<strong> system users UID <\/strong>is within the range of <strong>100<\/strong>.<\/li>\n<li style=\"text-align: justify;\"><strong>12<\/strong> \u2013 The fourth field refers to the primary group&#8217;s <strong>numerical identifier<\/strong> (<strong>GID<\/strong>) to which the user belongs. The primary group is the <strong>default group<\/strong> associated with the user. The group information is typically stored in the <strong>\/etc\/group <\/strong>file.<\/li>\n<li style=\"text-align: justify;\"><strong>man<\/strong> \u2013The fifth field contains additional information about the user, such as the user&#8217;s full name and other descriptions. In case of application, it contains details of the application. Here this field simply contains the same value as the <strong>username<\/strong> (<strong>man<\/strong>).<\/li>\n<li style=\"text-align: justify;\"><strong>\/var\/cache\/man<\/strong> \u2013 This is the user\u2019s home directory. Here <strong>man<\/strong>\u2019s home directory is <strong>\/var\/cache\/man<\/strong>.<\/li>\n<li style=\"text-align: justify;\"><strong>\/usr\/sbin\/nologin<\/strong> \u2013 This refers to the login shell for the user, which is the command-line interpreter or program that is run when the user logs into the system. In this case, the user man has <strong>\/usr\/sbin\/nologin <\/strong>as the login shell, which means they are not allowed to log in interactively. This is often used for <strong>system accounts<\/strong> or users who do not need shell access.<\/li>\n<\/ul>\n<\/div><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Counting_System_and_General_User\"><\/span>Counting System and General User<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">You can easily identify general users and system users with basic knowledge of <strong>Bash<\/strong> scripting. In the script below, I am going to count different types of users currently in the system based on the <strong>UID<\/strong> range.<\/p>\n<p style=\"text-align: justify;\"><strong>UIDs<\/strong> below <strong>1000<\/strong> are typically reserved for system users, while those <strong>1000<\/strong> and above are for regular user accounts. Run the following two commands to find the <strong>UID <\/strong>range for the <strong>system <\/strong>and <strong>regular <\/strong>user:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">grep UID_MIN \/etc\/login.defs<\/code><\/pre>\n<pre><code class=\"language-bash\" data-line=\"\">grep UID_MAX \/etc\/login.defs<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15296\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/7.-UID-range-for-system-and-general-user.png\" alt=\"UID range for system and general user\" width=\"825\" height=\"249\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/7.-UID-range-for-system-and-general-user.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/7.-UID-range-for-system-and-general-user-300x91.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/7.-UID-range-for-system-and-general-user-765x231.png 765w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p style=\"text-align: justify;\">To count the number of system and general users in Bash, please run the following Bash script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Number of total user\ntotal_user=$(wc -l &lt; \/etc\/passwd)\necho &quot;Number of total users in the system: $total_user&quot;\n\n# Loop through all users and check if they have superuser privileges\nregular_user=0\n\nwhile IFS=: read -r username _ uid _ _ _ _; do\nif (( uid &gt;= 1000 )); then\nregular_user=$((regular_user + 1))\nfi\ndone &lt; \/etc\/passwd\n\nsystem_user=$((total_user - regular_user))\necho &quot;Number of regular users in the system: $regular_user&quot;\necho &quot;Number of system users in the system: $system_user&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">This Bash script begins by using the <strong>wc <\/strong>command to count the number of lines in the <strong>\/etc\/passwd<\/strong> file, which corresponds to the total number of users on the system. The result is stored in the <strong>total_user <\/strong>variable.<\/p>\n<p style=\"text-align: justify;\">The script then utilizes a <strong>while loop<\/strong> to read each line of the <strong>\/etc\/passwd<\/strong> file, extracting the <strong>username<\/strong> and <strong>UID<\/strong> fields. It checks if the <strong>UID<\/strong> is greater than or equal to <strong>1000<\/strong>, It increments the <strong>regular_user<\/strong> counter for each regular user encountered. After the loop completes, it calculates the number of system users by subtracting <strong>regular_user<\/strong> from <strong>total_user<\/strong>, and both counts are displayed using the <strong>echo<\/strong> command.<\/div><\/div>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15297\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/8.-Counting-different-types-of-user-in-the-system.png\" alt=\"Counting different types of user in the system\" width=\"700\" height=\"188\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/8.-Counting-different-types-of-user-in-the-system.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/8.-Counting-different-types-of-user-in-the-system-300x81.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/8.-Counting-different-types-of-user-in-the-system-767x206.png 767w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/>Here the script shows the number of total users in the system is 48. Among them, 2 users are regular users and the rest of them are system users.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Checking_the_Existence_of_a_User\"><\/span>Checking the Existence of a User<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Using the <strong>getent<\/strong> command you can check whether a user with a specific name exists in the system:<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15298\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/9.-Checking-existence-of-user-in-the-system.png\" alt=\"Checking existence of user in the system\" width=\"700\" height=\"121\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/9.-Checking-existence-of-user-in-the-system.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/9.-Checking-existence-of-user-in-the-system-300x52.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/9.-Checking-existence-of-user-in-the-system-764x132.png 764w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/> Here, the user <strong>laku <\/strong>exists in the system hence <strong>getent passwd laku <\/strong>shows the output. However, <strong>getent passwd alina <\/strong>doesn\u2019t give any output because user <strong>alina <\/strong>doesn\u2019t exist in the system.<\/p>\n<p>You can also list down all the group users using the following command:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">getent group | cut -d: -f1<\/code><\/pre>\n<h2><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15299\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/10.-List-of-group-users-in-Bash.png\" alt=\"List of group users in Bash\" width=\"699\" height=\"379\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/10.-List-of-group-users-in-Bash.png 699w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/10.-List-of-group-users-in-Bash-300x163.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/10.-List-of-group-users-in-Bash-767x416.png 767w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><\/h2>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In conclusion, Getting a list of users in Bash is an important aspect of system administration and security. Knowing all present users of a system allows administrators to have better control over access and permissions. Hope now you can easily get all the users and groups with a simple Bash script.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"People_Also_Ask\"><\/span>People Also Ask<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"What_does_users_command_do_in_Linux\"><\/span>What does users command do in Linux?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The <strong>users <\/strong>command only prints the currently logged-in username in Linux. It doesn\u2019t print the whole list of users of the system.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_is_the_fourth_field_of_the_etcpasswd_file\"><\/span>What is the fourth field of the \/etc\/passwd file?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The fourth field of the <code class=\"\" data-line=\"\">\/etc\/passwd<\/code> file is for the Group ID, known as <strong>GID<\/strong>. The group ID, mainly a number determines the primary group of a user.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_I_list_users_of_a_specific_group_in_Linux\"><\/span>How to I list users of a specific group in Linux?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To print all the users of a specific group name, let&#8217;s say, <code class=\"\" data-line=\"\">group_name<\/code>, the <code class=\"\" data-line=\"\">getent group group_name | cut -d: -f4<\/code> command can be used. Just replace the <strong>group_name <\/strong>with your desired group name.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_can_I_switch_user_in_Linux\"><\/span>How can I switch user in Linux?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To switch between users in Linux, use the <a href=\"https:\/\/linuxsimply.com\/su-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>su command<\/strong><\/a>. In order to switch to a specific user, you simply need to provide the desired username after the <strong>su<\/strong> command as a command argument.<\/p>\n<p><script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [{\n    \"@type\": \"Question\",\n    \"name\": \"What does users command do in Linux?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"The users command only prints the currently logged-in username in Linux. It doesn\u2019t print the whole list of users of the system.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"What is the fourth field of the \/etc\/passwd file?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"The fourth field of the \/etc\/passwd file is for the Group ID, known as GID. The group ID, mainly a number determines the primary group of a user.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"How to I list users of a specific group in Linux?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"To print all the users of a specific group name, let's say, group_name, the getent group group_name | cut -d: -f4 command can be used. Just replace the group_name with your desired group name.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"How can I switch user in Linux?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"To switch between users in Linux, use the su command. In order to switch to a specific user, you simply need to provide the desired username after the su command as a command argument.\"\n    }\n  }]\n}\n<\/script><\/p>\n<p><span style=\"font-size: 18pt; color: #003366;\"><strong>Related Articles<\/strong><\/span><\/p>\n<ul>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/get-date\/\" target=\"_blank\" rel=\"noopener\">How to Get Date in Bash [2 Methods with Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/print-time\/\" target=\"_blank\" rel=\"noopener\">How to Print Time in Bash [2 Quick Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/current-time\/\" target=\"_blank\" rel=\"noopener\">How to Get Current Time in Bash [4 Practical Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/date-format\/\" target=\"_blank\" rel=\"noopener\">How to Use Date Format in Bash [5 Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/get-timestamp\/\" target=\"_blank\" rel=\"noopener\">How to Get Timestamp in Bash [2 Practical Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/copy-paste\/\" target=\"_blank\" rel=\"noopener\">How to Copy and Paste in Bash [2 Methods &amp; Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/\" target=\"_blank\" rel=\"noopener\">How to Read Password in Bash [3 Practical Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/send-email\/\" target=\"_blank\" rel=\"noopener\">How to Send Email in Bash [2 Easy Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/send-email-with-attachment\/\" target=\"_blank\" rel=\"noopener\">Bash Script to Send Email with Attachment [Step-by-Step Guide]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/get-ip-address\/\" target=\"_blank\" rel=\"noopener\">How to Get IP Address in Bash [3 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/find-and-replace\/\" target=\"_blank\" rel=\"noopener\">How to Find and Replace String in Bash [5 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/get-script-name\/\" target=\"_blank\" rel=\"noopener\">How to Get Script Name Using Bash Script? [3 Easy Ways]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/call-another-script\/\" target=\"_blank\" rel=\"noopener\">How to Call Another Script in Bash [2 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/generate-uuid\/\" target=\"_blank\" rel=\"noopener\">How to Generate UUID in Bash [3 Simple Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/write-to-file\/\" target=\"_blank\" rel=\"noopener\">3 Easy Ways to Write to a File in Bash Script<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/output-to-file\/\" target=\"_blank\" rel=\"noopener\">How to Write the Output to a File in Bash Script [5 Practical Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-in-bash\/\" target=\"_blank\" rel=\"noopener\">How to Create a List in Bash Scripts? [2 Easy Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/clear-history\/\" target=\"_blank\" rel=\"noopener\">How to Clear History in Bash [2 Practical Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/clear-screen\/\" target=\"_blank\" rel=\"noopener\">How to Clear Screen Using Bash Script? [2 Effective Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/check-ubuntu-version\/\" target=\"_blank\" rel=\"noopener\">How to Check Ubuntu Version Using Bash Scripts? [2 Methods]<\/a><\/strong><\/li>\n<\/ul>\n<hr \/>\n<p><strong>&lt;&lt; Go Back to <span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;28 Essential Bash Script Examples&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1065857,&quot;3&quot;:{&quot;1&quot;:0},&quot;10&quot;:1,&quot;11&quot;:4,&quot;12&quot;:0,&quot;17&quot;:1,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/\" target=\"_blank\" rel=\"noopener\">Bash Script Examples<\/a> <\/span>| <span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Scripting Basics&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:16768,&quot;10&quot;:1,&quot;11&quot;:4,&quot;17&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/\" target=\"_blank\" rel=\"noopener\">Bash Scripting Basics<\/a><\/span>\u00a0| <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/\" target=\"_blank\" rel=\"noopener\">Bash Scripting Tutorial<\/a><\/strong><\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-center kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;center&quot;,&quot;id&quot;:&quot;15281&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;How to List Users in Bash [2 Easy Ways]&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            <span class=\"kksr-muted\">Rate this post<\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>To list users in Bash utilize the \/etc\/passwd file. This file contains a lot of information about the users. You &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to List Users in Bash [2 Easy Ways]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#more-15281\" aria-label=\"Read more about How to List Users in Bash [2 Easy Ways]\">Read more<\/a><\/p>\n","protected":false},"author":314903,"featured_media":15300,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[114],"class_list":["post-15281","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-bash-script-examples","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to List Users in Bash [2 Easy Ways]<\/title>\n<meta name=\"description\" content=\"It is important to get the list of users in the system. This article talks about to easy ways of getting users list in Bash.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to List Users in Bash [2 Easy Ways]\" \/>\n<meta property=\"og:description\" content=\"It is important to get the list of users in the system. This article talks about to easy ways of getting users list in Bash.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/zahidlaku72\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-03T06:18:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-31T06:32:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/Bash-list-users.png\" \/>\n\t<meta property=\"og:image:width\" content=\"441\" \/>\n\t<meta property=\"og:image:height\" content=\"441\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Md Zahidul Islam Laku\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Md Zahidul Islam Laku\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/list-users\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/list-users\\\/\"},\"author\":{\"name\":\"Md Zahidul Islam Laku\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/26b37b2c7517d2c8702472bc3986ef21\"},\"headline\":\"How to List Users in Bash [2 Easy Ways]\",\"datePublished\":\"2023-08-03T06:18:08+00:00\",\"dateModified\":\"2023-12-31T06:32:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/list-users\\\/\"},\"wordCount\":1855,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/list-users\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/Bash-list-users.png\",\"keywords\":[\"bash script examples\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/list-users\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/list-users\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/list-users\\\/\",\"name\":\"How to List Users in Bash [2 Easy Ways]\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/list-users\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/list-users\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/Bash-list-users.png\",\"datePublished\":\"2023-08-03T06:18:08+00:00\",\"dateModified\":\"2023-12-31T06:32:18+00:00\",\"description\":\"It is important to get the list of users in the system. This article talks about to easy ways of getting users list in Bash.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/list-users\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/list-users\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/list-users\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/Bash-list-users.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/Bash-list-users.png\",\"width\":441,\"height\":441,\"caption\":\"Bash list users\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/list-users\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bash Scripting Tutorial\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Bash Scripting Basics\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Bash Script Examples\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"How to List Users in Bash [2 Easy Ways]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"name\":\"LinuxSimply\",\"description\":\"All About Linux\",\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/linuxsimply.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\",\"name\":\"LinuxSimply\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"width\":355,\"height\":48,\"caption\":\"LinuxSimply\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/26b37b2c7517d2c8702472bc3986ef21\",\"name\":\"Md Zahidul Islam Laku\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Md-Zahidul-Islam-Laku-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Md-Zahidul-Islam-Laku-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Md-Zahidul-Islam-Laku-II-96x96.png\",\"caption\":\"Md Zahidul Islam Laku\"},\"description\":\"Hey, I'm Zahidul Islam Laku currently working as a Linux Content Developer Executive at SOFTEKO. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). I write articles on a variety of tech topics including Linux. Learning and writing on Linux is nothing but fun as it gives me more power on my machine. What can be more efficient than interacting with the Operating System without Graphical User Interface! Read Full Bio\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/zahidlaku72\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/zahidlaku\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCnxMIaAb-nXO5XnMeEaNhpQ\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/laku\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to List Users in Bash [2 Easy Ways]","description":"It is important to get the list of users in the system. This article talks about to easy ways of getting users list in Bash.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/","og_locale":"en_US","og_type":"article","og_title":"How to List Users in Bash [2 Easy Ways]","og_description":"It is important to get the list of users in the system. This article talks about to easy ways of getting users list in Bash.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/zahidlaku72","article_published_time":"2023-08-03T06:18:08+00:00","article_modified_time":"2023-12-31T06:32:18+00:00","og_image":[{"width":441,"height":441,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/Bash-list-users.png","type":"image\/png"}],"author":"Md Zahidul Islam Laku","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Md Zahidul Islam Laku","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/"},"author":{"name":"Md Zahidul Islam Laku","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/26b37b2c7517d2c8702472bc3986ef21"},"headline":"How to List Users in Bash [2 Easy Ways]","datePublished":"2023-08-03T06:18:08+00:00","dateModified":"2023-12-31T06:32:18+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/"},"wordCount":1855,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/Bash-list-users.png","keywords":["bash script examples"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/","name":"How to List Users in Bash [2 Easy Ways]","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/Bash-list-users.png","datePublished":"2023-08-03T06:18:08+00:00","dateModified":"2023-12-31T06:32:18+00:00","description":"It is important to get the list of users in the system. This article talks about to easy ways of getting users list in Bash.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/Bash-list-users.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/Bash-list-users.png","width":441,"height":441,"caption":"Bash list users"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/linuxsimply.com\/"},{"@type":"ListItem","position":2,"name":"Bash Scripting Tutorial","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/"},{"@type":"ListItem","position":3,"name":"Bash Scripting Basics","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/"},{"@type":"ListItem","position":4,"name":"Bash Script Examples","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/"},{"@type":"ListItem","position":5,"name":"How to List Users in Bash [2 Easy Ways]"}]},{"@type":"WebSite","@id":"https:\/\/linuxsimply.com\/#website","url":"https:\/\/linuxsimply.com\/","name":"LinuxSimply","description":"All About Linux","publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/linuxsimply.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/linuxsimply.com\/#organization","name":"LinuxSimply","url":"https:\/\/linuxsimply.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","width":355,"height":48,"caption":"LinuxSimply"},"image":{"@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/26b37b2c7517d2c8702472bc3986ef21","name":"Md Zahidul Islam Laku","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Md-Zahidul-Islam-Laku-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Md-Zahidul-Islam-Laku-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Md-Zahidul-Islam-Laku-II-96x96.png","caption":"Md Zahidul Islam Laku"},"description":"Hey, I'm Zahidul Islam Laku currently working as a Linux Content Developer Executive at SOFTEKO. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). I write articles on a variety of tech topics including Linux. Learning and writing on Linux is nothing but fun as it gives me more power on my machine. What can be more efficient than interacting with the Operating System without Graphical User Interface! Read Full Bio","sameAs":["https:\/\/www.facebook.com\/zahidlaku72","https:\/\/www.linkedin.com\/in\/zahidlaku\/","https:\/\/www.youtube.com\/channel\/UCnxMIaAb-nXO5XnMeEaNhpQ"],"url":"https:\/\/linuxsimply.com\/author\/laku\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/15281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/users\/314903"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=15281"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/15281\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/15300"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=15281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=15281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=15281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}