How to solv “argument list too long: grep” error using grep

There was an unusual phenomenon in which grep did not work in a particular directory. The directory was a result of testing multiple url with a meg, and I thought it was a phenomenon that was caused by a large number of subfiles and directories, but the funny thing is that the grep works normally in the parent directory of that directory. 특정 디렉토리에서 grep이 동작하지 않는 특이한 현상이 있었습니다. 해당 디렉토리는 meg로 다수의 url을 테스팅한 결과였고, 하위 파일과 디렉토리가 많아서 발생하는 현상으로 생각했었는데, 웃긴게 해당 디렉토리의 상위 디렉토리에서 grep은 정상 동작합니다.

grep "hahwul" *
zsh: argument list too long: grep

I don’t know the cause, but I’m going to write out the case that I’ve solved. 원인은 알 수 없지만 제가 해결했던 케이스를 정리해봅니다.

using grep on parent directory

This is an easy solution for my case. doing a grep in the parent directory. However, if you randomly specify the location of the grep, the same error will appear, which is slightly insufficient to see as a solution. 제가 쉽게 해결한 부분인데, 상위 디렉토리에서 grep을 할 시 정상적으로 됩니다. 다만 grep의 위치를 임의로 해당 디렉토리를 지정했을 경우 동일하게 에러가 나타나기 때문에 해결 방법으로 보기엔 약간 미흡합니다.

cd ../
grep -r 'i-find-this-text' *

using grep with find+xargs

There is a way to search for the names of all the files with a find, read them with a xargs, and a grep. find로 모든 파일의 이름을 검색하고 읽어서 grep을 거는 방법이 있습니다.

find . -name "*" | xargs -n 20 grep 'i-find-this-text