分析日志t.log(访问量) ,将各个ip地址截取,并统计出现次数,并按从大到小排序
cat t.txt | cut -d’/‘ -f 3 | sort | uniq -c | sort -nr
http://192.168.200.10/index1.html
http://192.168.200.10/index2.html
http://192.168.200.20/index1.html
http://192.168.200.30/index1.html
http://192.168.200.40/index1.html
http://192.168.200.30/order.html
http://192.168.200.10/order.html
注:统计个数前要先sort,因为uniq 命令只过滤文本文件中重复出现的行列
统计连接到服务器的各个ip情况,并按连接数从大到小排序
netstat -anp | grep ESTABLISHED | awk -F “ “ ‘{print $5}’ | cut -d “:” -f 1|sort|uniq -c
注:简单的分割用cut方便,复杂一点的用awk(比如按照空格来分割)
使用tcpdump监听本机,将来自ip 192.168.200.1 , tcp端口为22的数据,保存输出到
tcpdump.log,用做将来数据分析
tcpdump -i ens33 host 192.168.135.1 and port 22 >> /opt/interview/tcpdump.log
Linux查看内存、io 读写、磁盘存储、端口占用、进程查看命令是什么
top, iotop, df -Ih , netstat -tunlp, ps -aux| grep “**”
注:io读写需要安装
使用Linux命令计算t2.txt第二列的和并输出
张三40
李四50
王五60
cat t2.txt | awk -F” “ ‘{sum+ =$2} END {print sum}’
写出统计/home/h 目录下所有文件个数和所有文件总行数的指令
find /home/h -name “.“ | wc -l
find /home/h -name “.“ | xargs wc -l
