Linux find/grep命令

一、Find

1)批量删除文件

find . -name "*.h~" -exec rm '{}' ;

2)定位文件某一行

find / -name "demo.conf" | egrep -v "default" | xargs grep -n "demo"  | head -1 | cut -d "/" -f 4

3)查找一级目录

find / -type d -maxdepth 1 -mindepth 1 | egrep -v "(default|global|htdoc)

4)替换文件某行

find / -name "demo.conf" | egrep -v "default" | xargs sed -i 's/demo/demo:test/g'

5)在文件某行后插入内容

find / -name "demo.conf" | xargs sed -i ''$(find / -name "demo.conf" | egrep -v "default" | xargs grep -n "demo"  | head -1 | cut -d ":" -f 4)'ademo
demo'

6)查找二进制文件

find -type f -a -perm  +700 | xargs file | grep "32-bit" | awk '{print $1}';

7)插入tab

find /kssl/HRP/cfg/ -name "proxy.conf.xml*" | xargs sed -i ''$(find /kssl/HRP/cfg/ -name "proxy.conf.xml*" | xargs grep -n "clientpolicy_update_freq"  | head -1 | cut -d ":" -f 2)'a\t		<clientpolicy><name>EnableSmartPA</name><value>NO</value></clientpolicy>'

 

 

二、Grep

grep get_default_error_string * -rFn --binary-files=without-match

 

三、正则表达式

原文地址:https://www.cnblogs.com/274914765qq/p/6055569.html