2020年8月6日星期四

Linux shell cmd of find and grep

1. find files by conditions 

find in-path [condition1] [-or/-and [condition2]] ...

ex. find .js files from current directory.
 find . -type f  -name *.js 

 find . type f -name *.js -or -name *.html  -not -name *.bak  -and -name *action*

2. grep keyword from found files.

grep contains functions from found files by find command. 
#print found results. | to xargs grep 
find . -type f  -name *.js  -print | xargs grep -E 'function \w+'

options:
-i:  ignore character case
-c: out the matched count
-o: out the matched value only
-v: out the unmatched lines
-r: --recursive. find the subfolders and files
-R--dereference-recursive: check symlink also.
-q: no matched values. Often used for matching check by  $? = 0
-E: using a regular expression. Equals egrep
-F: using real strings, can include *?. Equals fgrep.
-w: match a word
-x: match line. like ^pattern$
-m: match max count. 
-n: out the line number in the matched file.
-s: no error message.

3. find -print0 | xargs -0  for dealing \n and \0
= find -print0 |xargs --null





没有评论: