[root@centos7 data]#grep -v "/sbin/nologin" /etc/passwd root:x:0:0:root:/root:/bin/bash sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt lanfeng:x:1000:1000:lanfeng:/home/lanfeng:/bin/bash mageia:x:1100:1100::/home/linux:/bin/bash slackware:x:2002:2019::/home/slackware:/bin/tcsh 首先利用grep -v ,查找文本中/sbin/nologin所在行,并输出 [root@centos7 data]#grep -v "/sbin/nologin" /etc/passwd | cut -d: -f1 root sync shutdown halt lanfeng mageia slackware 用cut命令以:分号为分隔符,取第1列,即用户名