macOS의 한글 파일명에서 find, grep 하기
반응형

파일명에 한글이 포함된 경우, 심지어 띄어 쓰기까지 있는 경우 검색이 되지 않는다. 

 

이경우 아래 옵션을 쓴다.

  • find 
    • New line 대신 NULL 문자로 출력
    • -print0
      This primary always evaluates to true.  It prints the pathname of the current file to standard
      output, followed by an ASCII NUL character (character code 0).
  • xargs
    • 공백과 개행문자가 NULL로 처리되었음을 알립니다.
    • -0
      Change xargs to expect NUL (``\0'') characters as separators, instead of spaces and newlines.
      This is expected to be used in concert with the -print0 function in find(1).

현재 경로에서 모든 파일을 찾고 파일 안에서 ga_id 라는 문자열을 찾고 싶은 경우 아래와 같이 사용합니다.

find ./ -type f -print0 | xargs -0 grep ga_id

 

반응형