test2.txt:linux
[root@localhost test]#
说明:
多文件时,输出查询到的信息内容行时,会把文件的命名在行最前面输出并且加上":"作为标示符
实例7:grep不显示本身进程
命令:
ps aux|grep \[s]sh
ps aux | grep ssh | grep -v "grep"
输出:
[root@localhost test]# ps aux|grep ssh
root27200.00.0626561212 ?SsNov020:00 /usr/sbin/sshd
root168340.00.0880883288 ?Ss19:530:00 sshd: root@pts/0
root169010.00.061180764 pts/0S+20:310:00 grep ssh
[root@localhost test]# ps aux|grep \[s]sh]
[root@localhost test]# ps aux|grep \[s]sh
root27200.00.0626561212 ?SsNov020:00 /usr/sbin/sshd
root168340.00.0880883288 ?Ss19:530:00 sshd: root@pts/0
[root@localhost test]# ps aux | grep ssh | grep -v "grep"
root27200.00.0626561212 ?SsNov020:00 /usr/sbin/sshd
root168340.00.0880883288 ?Ss19:530:00 sshd: root@pts/0
说明:
实例8:找出已u开头的行内容
命令:
cat test.txt |grep ^u
输出:
[root@localhost test]# cat test.txt |grep ^u
ubuntu
ubuntu linux
[root@localhost test]#
说明:
实例9:输出非u开头的行内容
命令:
cat test.txt |grep ^[^u]
输出:
[root@localhost test]# cat test.txt |grep ^[^u]
hnlinux
peida.cnblogs.com
redhat
Redhat
linuxmint
[root@localhost test]#
说明:
实例10:输出以hat结尾的行内容
命令:
cat test.txt |grep hat$
输出:
[root@localhost test]# cat test.txt |grep hat$
redhat
Redhat
[root@localhost test]#
说明:
实例11:输出ip地址
命令:
ifconfig eth0|grep -E "([0-9]{1,3}\.){3}[0-9]"
输出:
[root@localhost test]# ifconfig eth0|grep "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}"
inet addr:192.168.120.204Bcast:192.168.120.255Mask:255.255.255.0
[root@localhost test]# ifconfig eth0|grep -E "([0-9]{1,3}\.){3}[0-9]"
inet addr:192.168.120.204Bcast:192.168.120.255Mask:255.255.255.0
[root@localhost test]#
说明:
【linux过滤的命令 linux过滤错误信息】 实例12:显示包含ed或者at字符的内容行
命令:
cat test.txt |grep -E "ed|at"
输出:
[root@localhost test]# cat test.txt |grep -E "peida|com"
peida.cnblogs.com
[root@localhost test]# cat test.txt |grep -E "ed|at"
redhat
Redhat
[root@localhost test]#
说明:
实例13:显示当前目录下面以.txt 结尾的文件中的所有包含每个字符串至少有7个连续小写字符的字符串的行
命令:
grep '[a-z]\{7\}' *.txt
输出:
[root@localhost test]# grep '[a-z]\{7\}' *.txt
test.txt:hnlinux
test.txt:peida.cnblogs.com
test.txt:linuxmint
[root@localhost test]#
实例14:日志文件过大,不好查看 , 我们要从中查看自己想要的内容 , 或者得到同一类数据,比如说没有404日志信息的
命令:
grep '.' access1.log|grep -Ev '404'access2.log
grep '.' access1.log|grep -Ev '(404|/photo/|/css/)'access2.log
grep '.' access1.log|grep -E '404'access2.log
输出:
[root@localhost test]# grep “.”access1.log|grep -Ev “404”access2.log
说明:上面3句命令前面两句是在当前目录下对access1.log文件进行查找,找到那些不包含404的行,把它们放到access2.log中,后面去掉’v’,即是把有404的行放入access2.log
linux过滤的命令的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于linux过滤错误信息、linux过滤的命令的信息别忘了在本站进行查找喔 。
推荐阅读
- 吃药网红直播,网红直播被观众催喝药 次日离世
- 角色扮演游戏教案看病,角色扮演医生游戏教案
- ios系统王者荣耀怎么转移到安卓,如何把ios王者荣耀转移到安卓
- java代码动态加密 javajar包加密
- 做新媒体如何赚钱快点,新媒体赚钱的方式
- pc像素经营游戏,像素游戏经营类游戏
- linux防火墙命令大全,linux防火墙规则表
- php用户登录带数据库 php制作登录界面数据库
- gis中如何使两条线,arcgis怎么把两条线合成一条线