20190829王老师发的面试题1、有一个日志文件access.log,内容如下

1、有一个日志文件access.log,内容如下

09:28:59 404 2003356554
09:29:00 200 2003232321
09:30:00 300 2003232321
09:36:00 500 2003232321
09:39:00 200 2003232321
09:40:00 400 2003232321
09:47:00 200 2003232321
...

现在需要统计第二列包含200这个字符的总行数,请写出命令?(只用awk能不能搞定)

最优答案:

[root@localhost ~]# awk '{sum[$2]++} END {print sum["200"]}' access.log
3

其他答案

[root@localhost ~]# awk '{sum[$2]+=1} END {for(a in sum) print  a,sum[a]}' access.log 
 1
300 1
400 1
200 3
404 1
500 1
[root@localhost ~]# awk '{sum[$2]+=1} END {for(a in sum) print  sum[a]}' access.log 
[root@localhost ~]# awk '{sum[$2]+=1} END {print sum["200"]}' access.log
3
[root@localhost ~]# awk '{++sum[$2]} END {print sum["200"]}' access.log 
3
[root@localhost ~]# awk '{sum[$2]+=1}END{for(i in sum)print i"\t"sum[i]}' access.log  | grep 200
200 3
[root@localhost ~]# awk '{print $2}' access.log | sort -n | grep 200 | wc -l
3
[root@localhost ~]# awk  '{print $2}' access.log | grep -w "200" | wc -l
3
[root@localhost ~]# awk '{if($2=="200")sum++}END{print sum}' access.log
3

2、请写出以下服务的默认端口号

SSH:22 Telnet:23 SMTP:25 POP3:110 DNS:53 FTP:20,21

HTTPS:443 HTTP:80 远程桌面:3389

3、linux命令题目

a.在/home目录创建admin目录

b.设置该目录的拥有组为admin

c.要求该组中成员对该目录有读写权限,且组中成员创建文件也属于admin组

[root@localhost ~]# mkdir /home/admin

[root@localhost ~]# chown .admin /home/admin
[root@localhost ~]# ls -ld /home/admin
drwxr-xr-x. 2 root admin 6 Aug 30 00:13 /home/admin

[root@localhost ~]# chmod g=rwxs /home/admin

4、linux下面挂载镜像rhel6.4.iso到/mnt

如果rhel6.4.iso只是硬盘里面的一个文件

[root@localhost ~]# mount rhel6.4.iso /mnt
mount: /dev/loop0 is write-protected, mounting read-only
#如果报错,手动执行loop
[root@localhost ~]# mount -o loop rhel6.4.iso /mnt
mount: /dev/loop0 is write-protected, mounting read-only

如果是个光驱:

[root@localhost ~]# mount /dev/cdrom /mnt

7、使用route添加默认网关172.41.8.100

route add default gw 172.18.8.100

8、查看nginx进程和nginx监听端口的命令

ps -ef | grep nginx
ss -ltn | grep nginx

9、linux查看系统资源情况

top
free
vmstat
iostat

猜你喜欢

转载自blog.51cto.com/14012942/2433698