Linux-常用命令例子

1.按照前面的URL统计PV,UV

统计日志:test.log
内容如下:
/a/click_1/stat.do token=11110
/a/click_2/stat.do token=11111
/a/click_1/stat.do token=11110
/a/click_2/stat.do token=11112
/a/click_2/stat.do token=11112
/a/click_3/stat.do token=12100
/a/click_3/stat.do token=12110

统计需求:按照前面的URL统计PV,UV
cat test.log |awk '{a[$1"#"$2]++}END{for(i in a){split(i,arr,"#"); print arr[1] "\t" a[i]; } }'|awk '{url_uv[$1]++; url_pv[$1]+=$2 }END {for(url in url_uv){ print "URL:" url "\tUV:" url_uv[url] "\t PV:" url_pv[url]} }'
结果:
URL:/a/click_1/stat.do UV:1 PV:2
URL:/a/click_2/stat.do UV:2 PV:3
URL:/a/click_3/stat.do UV:2 PV:2

2.查看apache的进程数

ps -aux | grep httpd | wc -l

3.分析日志查看当天的ip连接数

cat default-access_log | grep "10/Dec/2010" | awk '{print $2}' | sort | uniq -c | sort -nr

4.查看指定的ip在当天究竟访问了什么url

cat default-access_log | grep "10/Dec/2010" | grep “218.19.140.242″ | awk ‘{print $7}’ | sort | uniq -c | sort -nr

5.查看当天访问排行前10的url

cat default-access_log | grep "10/Dec/2010" | awk '{print $7}' | sort | uniq -c | sort -nr | head -n 10

6.看到指定的ip究竟干了什么

cat default-access_log | grep 218.19.140.242 | awk '{print $1″\t”$8}' | sort | uniq -c | sort -nr | less

7.查看访问次数最多的几个分钟(找到热点)

awk '{print $4}' default-access_log |cut -c 14-18|sort|uniq -c|sort -nr|head

8.同时查看多个文件的日志

tail -f chat_error.log -f  chat_biz.log   -f   chat_info.log  

9.查看进程的线程数

ps hH p<pid>|wc-l  或  cat /proc/<pid>/status

10.压缩文件

tar -zcvf /tmp/etc.tar.gz /etc

11.找出n天前修改的文件并删除

nohup find . -mtime +n -name *.txt -print | xargs rm -f &

12.找出小于2k的文件并删除

nohup find . -type f -size -2k  -name 2015-11-11.txt |  xargs rm -rf

13.查看占用cpu最高的进程

ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head

解释:

ps aux|head -1:显示标题

grep -v PID :不包含PID的行

sort -rn -k +3 -r r表示是结果倒序排列 n为以数值大小排序  -k +3则是针对第3列的内容进行排序  第三列表示cpu

14.查看占用内存最高的进程

ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4|head

15.通过进程号查询占用的端口

netstat -anp | grep pid

16.查看进程使用了多少内存

cat  /proc/<pid>/status

17.查看内存使用情况

free

18. 查看主机之间发送的信息

tcpdump -n  -X -c 10 dst  host 172.22.4.170  and port 3306

-n:不显示主机名,只显示 ip
-c  抓包个数
-e:输出的每行中都将包括数据链路层头部信息,例如源MAC和目标MAC。
-q:快速打印输出。即打印很少的协议相关信息,从而输出行都比较简短。
-X:输出包的头部数据,会以16进制和ASCII两种方式同时输出。
-XX:输出包的头部数据,会以16进制和ASCII两种方式同时输出,更详细。
-v:当分析和打印的时候,产生详细的输出。
-vv:产生比-v更详细的输出。
-vvv:产生比-vv更详细的输出。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值