一些面试题

来源:互联网 发布:java list转json字符串 编辑:程序博客网 时间:2024/05/20 11:27

1.如何查看端口8080的进程

netstat -anp | grep :8080

lsof -i :8080

2.在/tmp目录下创建test.txt文件,内容为:Hello,World!,用一个命令写出来。

echo "Hello,World" > /tmp/test.txt

3.叙述下列服务的默认端口号。

ftp:20,21

ssh:22

telnet:23

tomcat:8080

rsync:873

mysql:3306

4.nginx配置文件修改后,在不影响线上访问的前提下,用什么命令检查配置文件语法错误以及平滑重启nginx

检查语法命令: /usr/local/webserver/nginx/sbin/nginx -t

平滑重启命令:  /usr/local/webserver/nginx/sbin/nginx -s reload

5.凌晨01:59的时候,删除/abc目录下的全部子目录和全部文件,请写一个crontab定时任务

59 1 * * * /bin/rm -rf /abc/*

6.查找最后创建时间是3天前,后缀是*.log的文件并删除

find / -mtime +2 -name *.log -exec rm -rf {} \;

7.请将本地80端口的请求转发到8080端口,当前主机ip为172.17.111.101

iptables -t nat -A PREROUTING -d 172.17.111.101 -p tcp --dport 80 -j DNAT --to 172.17.111.101:8080

iptables -t nat -A PREROUTING -d 172.17.111.101 -p tcp --dport 80 -j DNAT --to-destination 172.17.111.101:8080

iptables -t nat -A PREROUTING -d 172.17.111.101 -p tcp --dport 80 -j REDIRECT --to-port 8080

8.从rizhi.log文件中提取包含“WARNING”或“ERROR”,同时不包含“IGNOR”的行,然后,提取以":"分割的第五个字段?

awk -F":" '/WARNING|ERROR/{print $5}' test | grep -v IGNOR

9.统计rizhi.log日志中每个IP地址访问次数,请根据访问量统计出前10个。

日志样例如下:

172.17.111.101 - [02/JUL/2016-23:22:22 +0800] -Get/HTTP/1.1 200 19

  cut -d" " -f1rizhi.log | sort | uniq -c | sort -nr | head -5

awk '{print $1}' rizhi.log | sort | uniq -c | sort -nr | head -5

10.写一个脚本,判断172.17.111.0/24的网络里,哪些ip能ping通

#!/bin/bash

for i in 'seq 255'

do

(

ping 172.17.111.$i &>/dev/null

if [ $? -eq 0 ]

then

echo "172.17.111.$i" >>/tmp/ip.txt

fi

)

done 

11.假设你有一个名为‘abc’的表,它存在多个字段,如‘createtime’和‘engine’。名为engine的字段由Memory和MyIsam两种数值组成,如何只列出‘createtime’和‘engine’这两列并且engine的值为MyIsam

select createtime,engine from abc where engine=MyIsam

0 0