-w 精准比配
把一个目录下,过滤所有*.php文档中含有eval的行 grep -r --include="*.php" 'eval' /data/
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 passwd bin: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 passwd 2: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 passwd 1: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 passwd root: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示列
[root@mingming grep]# grep '[0-9]'passwd root: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' passw root: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' passwd root: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\}' passwd root: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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。