环境准备
服务器系统 | Centos7.5 |
---|---|
内存 | 1G |
CPU | 2核 |
IP地址 | 192.168.46.181 |
cut命令用于文本处理。通过选择列,可以使用此命令从文件中提取文本的一部分。
cat /etc/passwd | cut -d ':' -f 1
统计系统有多少用户
cat /etc/passwd | cut -d : -f 1 | sort | wc -l
统计系统当前可以登录的用户有多少个
cat /etc/passwd | grep '/bin/bash' | wc -l
shell统计不能登录系统的用户
vim user.sh
#!/bin/bash
user_num=`cat /etc/passwd | grep '/bin/bash' | wc -l`
total_num=`cat /etc/passwd |wc -l`
nologin_user=$(($total_num-$user_num))
echo "不能登录系统的用户有: $nologin_user"
第二种方法或利用grep命令统计不能登录系统的用户
grep -v '/bin/bash' /etc/passwd | wc -l
grep -vc '/bin/bash' /etc/passwd