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:
[email protected]:~/scripts$ bash listuser1.sh
The total users are as follows..
Please feel free to comment on this.
Latest posts by Surendra Anne (see all)
- Understanding AWS “The services” Part – II - June 8, 2016
- Understanding AWS(Amazon Web services) “The Cloud” Part – I - May 11, 2016
- 16 ls command examples for newbe - April 20, 2016
- Understanding DOCKER containers in Linux? - April 19, 2016
- What is puppet? Why Linux/Unix users require it? - April 13, 2016