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

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...