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.
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.
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