您好,登錄后才能下訂單哦!
-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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。