This is a small how to on listing all the users in a box. This is bit tricky but if you give a thought you will realize that user info is in passwd file, so if you can grep the first field then it’s done.
The passwd file content for your reference
gdm:x:113:120:Gnome Display Manager:/var/lib/gdm:/bin/false
surendra:x:1000:1000:surendra,,,:/home/surendra:/bin/bash
mediatomb:x:114:123:MediaTomb Server,,,:/var/lib/mediatomb:/usr/sbin/nologin
haldaemon:x:115:124:Hardware abstraction layer,,,:/var/run/hald:/bin/false
ntop:x:116:126::/var/lib/ntop:/bin/false
How to get only user values?
Use cut command to cut the fields..
cat /etc/passwd | cut -d: -f1
Let me explain above command
we are opening file /etc/passwd with cat command and then redirecting output to a cut command which will cut the first field(-f1) ie user ID field using : as delineated(-d:). As you know passwd file content are separated with colon(:)
Sample output of the above command
cat /etc/passwd | cut -d: -f1 kernoops pulse rtkit saned hplip gdm surendra mediatomb haldaemon ntop
This is how we can list all the users. If you want to list all the groups in the machine we can use below command
cat /etc/group | cut -d: -f1
Please share your thoughts on this, how you do if you have same situation.
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018