首页 > 代码库 > Linux find/grep命令

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 ‘i/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\ndemo‘

 

参考:http://blog.jobbole.com/48931/

 

二、Grep

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

 

三、正则表达式

http://www.cnblogs.com/yirlin/archive/2006/04/12/373222.html
http://www.jb51.net/article/31235.htm

Linux find/grep命令