Simplest way is to use builtin command compgen. To list users by using this command use -u option as shown below.
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
Sample clipped output:
surendra@ubuntu:~/scripts$ bash listuser1.sh
The total users are as follows..
Please feel free to comment on this.
Latest posts by Surendra Anne (see all)
- 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
- Online training on Linux Bash shell scripting - February 8, 2018