1.shell笔试题
# cat /etc/passwdroot:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin
rtkit:x:499:497:RealtimeKit:/proc:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
saslauth:x:498:76:"Saslauthd user":/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
pulse:x:497:496:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
neil:x:500:500::/home/neil:/bin/bash
test:x:501:501::/home/test:/bin/bash
yulian:x:503:503::/home/yulian:/bin/bash
puppet:x:52:52:Puppet:/var/lib/puppet:/sbin/nologin
jboss:x:504:504::/home/jboss:/bin/bash
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
release:x:505:505::/home/release:/bin/bash
redis:x:496:493:Redis Server:/var/lib/redis:/sbin/nologin
mongodb:x:184:492:MongoDB Database Server:/var/lib/mongodb:/sbin/nologin
fang:x:506:506::/home/fang:/bin/bash
roundup:x:495:491:Roundup Issue Tracker:/var/lib/roundup:/sbin/nologin
exim:x:93:93::/var/spool/exim:/sbin/nologin
dial:x:507:507::/home/dial:/bin/bash
share:x:508:508::/home/share:/bin/bash
结果:
/(home)/(.*)?:
只能匹配到下面的部分
/home/neil:
/home/test:
/home/yulian:
/home/jboss:
/home/release:
/home/fang:
/home/dial:
/home/share:
2.
linux匹配密码文件中前后一样的内容
第一种:做转义
grep "^(.*):.*1$" /etc/passwd
第二种,加上-E不做转义
3.添加一个用户
useradd alexdsb
4.查看这个文件
cat /etc/passwd
[root@localhost ~]# grep 'home' /etc/passwd
alex:x:1000:1000::/home/alex:/bin/bash
[root@localhost ~]# cat /etc/passwd|grep 'home'
alex:x:1000:1000::/home/alex:/bin/bash
[root@localhost ~]# grep 'home' /etc/passwd|awk -F: '{print $6}'
/home/alex
[root@localhost ~]# useradd alex10
[root@localhost ~]# grep 'home' /etc/passwd|awk -F: '{print $6}'
/home/alex
/home/alex10
#注意:上边的{print $6}表示的是打印:的第几个隔开的(自己理解)