Linux命令(84)之uniq

linux命令之uniq

1.uniq介绍

linux命令uniq是用来删除经过排序后的数据的重复记录。uniq去重只能去除连续的重复行,所以一般先用sort排序,再去重统计重复的数据

2.uniq用法

uniq [参数]

uniq参数
参数说明
-c统计重复的数据

3.实例

3.1.统计http access.log文件中状态码

命令:

cat access.log | awk '{print $9}' | sort | uniq -c

[root@centos79 nginx]# pwd
/var/log/nginx
[root@centos79 nginx]# ls
access.log  error.log
[root@centos79 nginx]# cat access.log | awk '{print $9}' | sort | uniq -c
      4 200
      2 404
[root@centos79 nginx]# 

3.2.统计http access.log文件中谁访问过网站

命令:

cat access.log | awk '{print $1}' | uniq -c | sort -nr

[root@centos79 nginx]# pwd
/var/log/nginx
[root@centos79 nginx]# ls
access.log  error.log
[root@centos79 nginx]# cat access.log | awk '{print $1}' | uniq -c | sort -nr
      6 192.168.10.1
[root@centos79 nginx]# 

3.3.统计/etc/passwd中每种shell的使用情况

命令:

cat /etc/passwd | cut -d: -f 7 | uniq -c | sort -nr
 

[root@centos79 nginx]# cat /etc/passwd | cut -d: -f 7 | uniq -c | sort -nr
     36 /sbin/nologin
      4 /sbin/nologin
      4 /bin/bash
      2 /bin/bash
      1 /sbin/shutdown
      1 /sbin/nologin
      1 /sbin/halt
      1 /bin/sync
      1 /bin/bash
[root@centos79 nginx]# 

3.4.统计http access.log文件中访问次数最多的前两个ip地址,以及出现次数最多的两个状态码

命令:

cat access.log |awk '{print $1,$9}' | uniq -c | sort -r | head -2

[root@cent79-2 nginx]#  cat access.log |awk '{print $1,$9}' | uniq -c | sort -r | head -2
      4 192.168.10.1 200
      2 192.168.10.1 404
[root@cent79-2 nginx]# 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小黑要上天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值