cat /etc/passwd |grep -v nologin |grep -v false
时间: 2023-12-19 21:07:22 浏览: 28
As an AI language model, I don't have access to the file system, so I cannot execute the command. However, I can explain what the command does:
This command lists the contents of the file /etc/passwd and filters out any lines that contain the words "nologin" or "false". The vertical bar symbol "|" is used to pass the output of the first command (cat /etc/passwd) as input to the second command (grep -v nologin | grep -v false). The "grep -v" option is used to exclude lines that match the specified pattern.
相关问题
#!/bin/bash users=$(cut -d: -f1 /etc/passwd) for user in $users do if [[ $(getent passwd $user | cut -d: -f3) -ge 1000 ]] then if [[ $(chage -l $user | grep "Password expires" | grep "密码过期时间" | cut -d: -f2 | tr -d ' ') == "never" || $(chage -l $user | grep "Password expires" | grep "密码过期时间" | cut -d: -f2 | tr -d ' ') == "从不" ]] then echo "$user: Password never expires" else expire_date=$(date -d "$(chage -l $user | grep "Password expires" | cut -d: -f2 | tr -d ' ')" +%s) current_date=$(date +%s) if [[ $expire_date -lt $current_date ]] then echo "$(hostname -I | awk '{print $1}'), $user: Password has expired" else echo "$user: Password will expire on $(chage -l $user | grep "Password expires" | cut -d: -f2 | tr -d ' ')" fi fi else account_status=$(passwd -S $user | awk '{print $2}') if [[ "$account_status" == "L" ]]; then echo "$(hostname -I | awk '{print $1}'), User $user: account locked!" fi fi done这段代码去掉筛选非系统用户
可以将第4行改为:
```
users=$(cut -d: -f1 /etc/passwd | grep -v -E "nologin|false|sync|shutdown|halt")
```
这样就会排除掉系统用户了。
统计/etc/passwd中nologin出现次数
好的,让我来解决这个问题。您可以使用以下命令来统计/etc/passwd中nologin出现的次数:
grep -o 'nologin' /etc/passwd | wc -l
这个命令使用grep命令查找/etc/passwd中nologin字符串,并使用管道将结果传递给wc命令。wc命令用于计算字符串出现的次数,并显示最终结果。