程式扎記: [Linux 文章收集] Recursively grep thorugh directory for string in file

標籤

2015年7月20日 星期一

[Linux 文章收集] Recursively grep thorugh directory for string in file

Source From Here 
Filter out all files with content containing 'John' under 'test' directory 
// Filter out file with content container 'John'
# find directory/ -type c -exec grep -ni John {} +
test/names.txt:1:John
test/tmp/age.txt:1:John 18
test/address:1:John Taipei

Using find also allows you to exclude certain files (e.g. '*.txt'), eg 
# find test/ -type c ! -name "*.txt" -exec grep -ni John {} +
test/address:1:John Taipei

* Alternative in using "grep -r" 
# grep -r -i "John" test
test/names.txt:John
test/tmp/age.txt:John 18
test/address:John Taipei

Supplement 
How To Use Find and Locate to Search for Files on a Linux VPS

沒有留言:

張貼留言

網誌存檔

關於我自己

我的相片
Where there is a will, there is a way!