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
haldaemon:x:115:124:Hardware abstraction layer,,,:/var/run/hald:/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)
- 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
- wget download a file to a directory in Linux/Unix - June 4, 2018
- GIT: How to compare two GIT branches? - June 3, 2018