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)
- Puppet: How to install a package/software - October 16, 2016
- Luke Kanies is no more Puppet CEO - September 27, 2016
- Puppet terminology for newbe Linux users - September 3, 2016
- Understanding AWS “The services” Part – II - June 8, 2016
- Understanding AWS(Amazon Web services) “The Cloud” Part – I - May 11, 2016