This is a small script/command to list users in the machine. Some times it’s required to check how many users are there in the system and list them all or count the users.

Simplest way is to use builtin command compgen. To list users by using this command use -u option as shown below.

compgen -u

#!/bin/bash
VAR1=$(cut -d: -f1 /etc/passwd)
echo -e “The users in the system as fallows..n $VAR1 n Completed listing users..!”
echo “Total number of users are $(cat /etc/passwd | wc -l)”

Save this file as listusers1.sh and execute this script which will list all the users.

Execute the script

Step1:change permissions to execute permissions as below

chmod +x listuser1.sh

Step2: Executing shell script

bash listuser1.sh

Sample clipped output:

surendra@ubuntu:~/scripts$ bash listuser1.sh 
The total users are as follows..
root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
proxy
www-data
backup
list
irc
gnats
nobody
libuuid
syslog
messagebus
colord
lightdm
whoopsie
avahi-autoipd
avahi
usbmux
kernoops
pulse
rtkit
saned
speech-dispatcher
hplip
surendra
libvirt-qemu
libvirt-dnsmasq
sshd
uml-net
munin
temp
sagar


Please feel free to comment on this.


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.