在程序维护过程中,有时需要在某个目录及其所属子目录的所有文件中查找某一个字符串,为此可用下面两种方法(假设在*.cp文件中查找字符串”abc”,结果放在文件out中):
(1)cat /dev/null > out
find ./ -name “*.cp” -exec grep “abc”{} >> out
(2)find ./ -name “*.cp” | xargs grep “abc” > out
推荐使用第二种方法,因其系统开销小、速度快。
在程序维护过程中,有时需要在某个目录及其所属子目录的所有文件中查找某一个字符串,为此可用下面两种方法(假设在*.cp文件中查找字符串”abc”,结果放在文件out中):
(1)cat /dev/null > out
find ./ -name “*.cp” -exec grep “abc”{} >> out
(2)find ./ -name “*.cp” | xargs grep “abc” > out
推荐使用第二种方法,因其系统开销小、速度快。