grep
发表于:2025-01-20 作者:千家信息网编辑
千家信息网最后更新 2025年01月20日,扩展-w 精准比配把一个目录下,过滤所有*.php文档中含有eval的行 grep -r --include="*.php" 'eval' /data/9.1 正则介绍_grep上grep [-cin
千家信息网最后更新 2025年01月20日grep
扩展
-w 精准比配
把一个目录下,过滤所有*.php文档中含有eval的行 grep -r --include="*.php" 'eval' /data/
9.1 正则介绍_grep上
grep [-cinvABC]'word'filename
[root@mingming ~]# mkdir grep[root@mingming ~]# cd grep[root@mingming grep]# cp /etc/passwd .[root@mingming grep]# lspasswd[root@mingming grep]# grep nologin passwdbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinmail:x:8:12:mail:/var/spool/mail:/sbin/nologinuucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologingopher:x:13:30:gopher:/var/gopher:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologinnobody:x:99:99:Nobody:/:/sbin/nologindbus:x:81:81:System message bus:/:/sbin/nologinvcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologinrpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologinsaslauth:x:499:76:"Saslauthd user":/var/empty/saslauth:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinrpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologinnfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologinhaldaemon:x:68:68:HAL daemon:/:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
-c行数
[root@mingming grep]# grep -c nologin passwd20
-i不区分大小写
-n显示行数
[root@mingming grep]# grep -n nologin passwd2:bin:x:1:1:bin:/bin:/sbin/nologin3:daemon:x:2:2:daemon:/sbin:/sbin/nologin4:adm:x:3:4:adm:/var/adm:/sbin/nologin5:lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin9:mail:x:8:12:mail:/var/spool/mail:/sbin/nologin10:uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin11:operator:x:11:0:operator:/root:/sbin/nologin12:games:x:12:100:games:/usr/games:/sbin/nologin13:gopher:x:13:30:gopher:/var/gopher:/sbin/nologin14:ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin15:nobody:x:99:99:Nobody:/:/sbin/nologin16:dbus:x:81:81:System message bus:/:/sbin/nologin17:vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin18:rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin19:saslauth:x:499:76:"Saslauthd user":/var/empty/saslauth:/sbin/nologin20:postfix:x:89:89::/var/spool/postfix:/sbin/nologin21:rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin22:nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin23:haldaemon:x:68:68:HAL daemon:/:/sbin/nologin24:sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
-v取反
[root@mingming grep]# grep -nv nologin passwd1:root:x:0:0:root:/root:/bin/bash7:sync:x:5:0:sync:/sbin:/bin/sync7:shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown8:halt:x:7:0:halt:/sbin:/sbin/halt25:smbuser1:x:500:500::/home/smbuser1:/bin/bash
-r遍历所有子目录
-A后面跟数字,过滤出符合要求的行以及下面n行
grep -A2 root passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologin--operator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologingopher:x:13:30:gopher:/var/gopher:/sbin/nologin
-B同上,过滤出符合要求的行以及上面n行
-C同上,过滤出符合要求的行以及上下面n行 grep/egrep示列
* >=0次*前面的字符
. 任意一个字符
? 0个1个?前面的字符
+ >=1个+前面的字符
.* 通配
| 或者
[root@mingming grep]# grep '[0-9]'passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinuucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologingopher:x:13:30:gopher:/var/gopher:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologinnobody:x:99:99:Nobody:/:/sbin/nologindbus:x:81:81:System message bus:/:/sbin/nologinvcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologinrpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologinsaslauth:x:499:76:"Saslauthd user":/var/empty/saslauth:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinrpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologinnfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologinhaldaemon:x:68:68:HAL daemon:/:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologinsmbuser1:x:500:500::/home/smbuser1:/bin/bash[root@mingming grep]# grep -n '^#' inittab1:# inittab is only used by upstart for the default runlevel.2:#3:# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.4:#6:#7:# Individual runlevels are started by /etc/init/rc.conf8:#9:# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf10:#12:# with configuration in /etc/sysconfig/init.13:#14:# For information on how to write upstart event handlers, or how16:#18:# 0 - halt (Do NOT set initdefault to this)19:# 1 - Single user mode20:# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)21:# 3 - Full multiuser mode22:# 4 - unused23:# 5 - X1124:# 6 - reboot (Do NOT set initdefault to this)25:#[root@mingming grep]# grep -nv '^#' inittab5: System initialization is started by /etc/init/rcS.conf11: Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,15: upstart works, see init(5), init(8), and initctl(8).17: Default runlevel. The runlevels used are:26:id:3:initdefault:
非0-9的过滤出来
[root@mingming grep]# grep '[^0-9]' inittab# inittab is only used by upstart for the default runlevel.## ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.# System initialization is started by /etc/init/rcS.conf## Individual runlevels are started by /etc/init/rc.conf## Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,# with configuration in /etc/sysconfig/init.## For information on how to write upstart event handlers, or how upstart works, see init(5), init(8), and initctl(8).# Default runlevel. The runlevels used are:# 0 - halt (Do NOT set initdefault to this)# 1 - Single user mode# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)# 3 - Full multiuser mode# 4 - unused# 5 - X11# 6 - reboot (Do NOT set initdefault to this)#id:3:initdefault:
[root@mingming grep]# grep 'r.o' passwroot:x:0:0:root:/root:/bin/bashhalt:x:7:0:halt:/sbin:/sbin/haltriomail:x:8:12:mail:/var/spool/mail:/sbin/nologinr.ooperator:x:11:0:operator:/root:/sbin/nologin[root@mingming grep]# grep 'r.o' passwdroot:x:0:0:root:/root:/bin/bashoperator:x:11:0:operator:/root:/sbin/nologin[root@mingming grep]# vin passwd-bash: vin: command not found[root@mingming grep]# vim passwd[root@mingming grep]# grep 'r.o' passwdroot:x:0:0:root:/root:/bin/bashhalt:x:7:0:halt:/sbin:/sbin/haltriomail:x:8:12:mail:/var/spool/mail:/sbin/nologinr.ooperator:x:11:0:operator:/root:/sbin/nologin[root@mingming grep]# grep 'o*o' passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltriomail:x:8:12:mail:/var/spool/mail:/sbin/nologinr.ouucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologingopher:x:13:30:gopher:/var/gopher:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologinnobody:x:99:99:Nobody:/:/sbin/nologindbus:x:81:81:System message bus:/:/sbin/nologinvcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologinrpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologinsaslauth:x:499:76:"Saslauthd user":/var/empty/saslauth:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinrpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologinnfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologinhaldaemon:x:68:68:HAL daemon:/:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologinsmbuser1:x:500:500::/home/smbuser1:/bin/bash[root@mingming grep]# grep '.*' passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltriomail:x:8:12:mail:/var/spool/mail:/sbin/nologinr.ouucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologingopher:x:13:30:gopher:/var/gopher:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologinnobody:x:99:99:Nobody:/:/sbin/nologindbus:x:81:81:System message bus:/:/sbin/nologinvcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologinrpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologinsaslauth:x:499:76:"Saslauthd user":/var/empty/saslauth:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinrpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologinnfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologinhaldaemon:x:68:68:HAL daemon:/:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologinsmbuser1:x:500:500::/home/smbuser1:/bin/bash
匹配两个o
[root@mingming grep]# grep 'o\{2\}' passwdroot:x:0:0:root:/root:/bin/bashlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinmail:x:8:12:mail:/var/spool/mail:/sbin/nologinr.ouucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologin[root@mingming grep]# egrep 'o{2}' passwdroot:x:0:0:root:/root:/bin/bashlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinmail:x:8:12:mail:/var/spool/mail:/sbin/nologinr.ouucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologin[root@mingming grep]# grep -E 'o{2}' passwdroot:x:0:0:root:/root:/bin/bashlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinmail:x:8:12:mail:/var/spool/mail:/sbin/nologinr.ouucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologin
字符
精准
两个
大小
子目
子目录
数字
文档
正则
目录
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
如何搭建自己的服务器视频教程
基础软件开发
小米浏览器如何关闭网络安全检测
公司架设服务器有什么用
搜索网络安全的话
海南创新网络技术服务怎么样
硬盘和cpu能装服务器吗
简单实用的网络技术
我县网络安全活动
华为全球最大数据库
网络安全近三年出现的问题
崩坏学园服务器
网络安全和信息化相关知识题库
浙江天搜科技移动互联网
适合做家庭服务器的cpu
qt办公软件开发
我的世界服务器阿尔宙斯能不能刷
移动模块如何发送消息给服务器
软件开发公司毛利怎么计算
40岁还能做软件开发吗
数据库原理与技术第五章答案
简单实用的网络技术
朝阳区综合软件开发包括什么
文件服务器域
什么时候用内存数据库redis
信息发布小软件开发
esxi服务器新增物理内存
苏州戴尔服务器类别查看
40岁还能做软件开发吗
樱花服务器localhost