This is a small script/command to list users in the machine. Some times its 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
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
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.
0 comments:
Post a Comment