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.

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.