문제

I know I can use grep to find a word in all the files present in a folder like this

grep -rn core .

But my current directory has many sub-directories and I just want to search in all xml files present in the current directory and its all sub directories. How can I do that ?

I tried this

grep -rn core *.xml // Does not work

But it searches for xml files present in the current directory only. It does not do it recursively.

도움이 되었습니까?

해결책

Try the --include option

grep -R --include="*.xml" "pattern" /path/to/dir

Reference: Grep Include Only *.txt File Pattern When Running Recursive Mode

다른 팁

Use find:

find /path/to/dir -name '*.xml' -exec grep -H 'pattern' {} \;

I use this often:

grep 'pattern' /path/to/dir/**/*.xml

EDIT:

with zsh

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top