linux find grep combination

Copyright: Complimentary more micro-business marketing courses, please pay attention to the public No. [shop]! https://blog.csdn.net/gzw1623231307/article/details/56475433

1. Find all ".h" file

find /PATH -name "*.h"

2. Find the file containing the "helloworld" string of all ".h" file

find /PATH -name "*.h" -exec grep -in "helloworld" {} \;

find /PATH -name "*.h" | xargs grep -in "helloworld"

3. Find all files ".h" and ".c" file containing "helloworld" string

find /PATH /( -name "*.h" -or -name "*.c" /) -exec grep -in "helloworld" {} \;

4. Find the file containing the "helloworld" string of non-backup file

find /PATH /( -not -name "*~" /) -exec grep -in "helloworld" {} \;

Note: /PATHTo find the path, the default is the current path. Must \ belt -exec parameters; at the end, otherwise it will prompt "find: missing" "parameter" -exec.



Use find and xargs
1. pathname find -options [-print -exec -ok]
-optinos
1) -name: Find by file name
find ~ -name "* .txt" -print
find ~ -name "[az] [0 -9] .txt "-print
2) -perm: find files according to the rights
find ~ -perm 755 -print lookup file permissions 755
find ~ -perm 007 -print 7 looks for a location on the file permissions o
find ~ -perm 4000 -print finds files with the suid
3) -prune
find the next not the current directory
4) -user and -nouser
Find ~ -user zhao -print find the main document file is zhao
find ~ -nouser -print lookup file owner has deleted files
5) -group and -nogroup
the Find ~ -group zhao -print Find files group file is zhao
6) in chronological
find ~ -mtime -5 -print file modification time in a file within 5 days
find ~ -mtime file +3 -print file modification time in three days before the
find ~ -newer file1 -print find new file than the file file1
7) Find by type
find ~ -type d -print Find all directories
8) according to the size of the
file find ~ -size + 1000000C -print lookup file size is greater than 1,000,000 bytes (1M) to
9) to find this file system is located inside the paper
find / -name "* .txt "-mount -print
-exec, -OK: Find command for executing the file matches the parameters given shell command, the command corresponding to the form: 'command' {} \;
-OK before execution command to confirm
find ~ - F {-l -exec LS type} \;
find / -name "* .log" +5 -OK RM -mtime {} \;
find -name Core RM -exec {} \;.
use -x dev parameter
prevented find search for other partitions
. find -size 0 -exec rm {} \;
delete the file size is 0
2. xargs with -exec function is similar to
the Find ~ the -type f | xargs LS the -l
the Find / -name "* .log" the -type -print f | xargs grep -i DB0
the Find the -type f |. xargs grep -i "Mary"
to retrieve Mary string in all files
ls * ~ | xargs rm -rf
delete all files ending with ~



svn svn folder filter

1.使用管道进行双层“过滤”,其中第二次grep使用了 -v选项,即 逆向匹配,打印出不匹配的行
     grep -r ' function_name ' * | grep -v '.svn'

    2.或者更简单一些,直接使用 --exclude-dir选项,即 指定排除目录,注意svn前的  \.
     grep -r --exclude-dir=\.svn 'function_name' * 



grep多个过滤条件

1、或操作

  grep -E '123|abc' filename  // 找出文件(filename)中包含123或者包含abc的行
  egrep '123|abc' filename    // 用egrep同样可以实现
  awk '/123|abc/' filename   // awk 的实现方式

2、与操作

  grep pattern1 files | grep pattern2 :显示既匹配 pattern1 又匹配 pattern2 的行。

 

3、其他操作

grep -i pattern files :不区分大小写地搜索。默认情况区分大小写,
grep -l pattern files :只列出匹配的文件名,
grep -L pattern files :列出不匹配的文件名,
grep -w pattern files :只匹配整个单词,而不是字符串的一部分(如匹配‘magic’,而不是‘magical’),
grep -C number pattern files :匹配的上下文分别显示[number]行,


find过滤svn文件夹

find -type f ! -path '*/.svn/*'



Guess you like

Origin blog.csdn.net/gzw1623231307/article/details/56475433