歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> grep command: Recursively Search All Files For A String

grep command: Recursively Search All Files For A String

日期:2017/3/1 15:28:30   编辑:關於Linux
grep command: Recursively Search All Files For A String grep command: Recursively Search All Files For A String cd /path/to/dir grep -r "word" . grep -r "string" . Ignore case distinctions: grep -ri "word" . To display print only the filenames with GNU grep, enter: grep -r -l "foo" . You can also specify directory name: grep -r -l "foo" /path/to/dir/*.c find command: Recursively Search All Files For A String find command is recommend because of speed and ability to deal with filenames that contain spaces. cd /path/to/dir find . -type f -exec grep -l "word" {} + find . -type f -exec grep -l "seting" {} + find . -type f -exec grep -l "foo" {} + Older UNIX version should use xargs to speed up things: find /path/to/dir -type f | xargs grep -l "foo" It is good idea to pass -print0 option to find command that it can deal with filenames that contain spaces or other metacharacters: find /path/to/dir -type f -print0 | xargs -0 grep -l "foo"
Copyright © Linux教程網 All Rights Reserved