![find 명령(grep 사용)의 출력을 로그 파일로 리디렉션하려면 어떻게 해야 합니까?](https://linux55.com/image/31874/find%20%EB%AA%85%EB%A0%B9(grep%20%EC%82%AC%EC%9A%A9)%EC%9D%98%20%EC%B6%9C%EB%A0%A5%EC%9D%84%20%EB%A1%9C%EA%B7%B8%20%ED%8C%8C%EC%9D%BC%EB%A1%9C%20%EB%A6%AC%EB%94%94%EB%A0%89%EC%85%98%ED%95%98%EB%A0%A4%EB%A9%B4%20%EC%96%B4%EB%96%BB%EA%B2%8C%20%ED%95%B4%EC%95%BC%20%ED%95%A9%EB%8B%88%EA%B9%8C%3F.png)
"검색 문자열" 패턴을 포함하는 모든 파일을 검색하는 코드를 고려해보세요.
bash-3.2$ # The below find works fine..
bash-3.2$ find . -type f -exec grep -il "search string" {} \;
bash-3.2$ # But I am unable to redirect output to a log file..
bash-3.2$ find . -type f -exec grep -il "search string" {} \ > log.txt
find: incomplete statement
bash-3.2$
Solaris 매뉴얼 페이지에서찾다:
-exec command True if the executed command returns a zero value as exit status. The end of command must be punctuated by an escaped semicolon. A command argument {} is replaced by the current path name.
따라서 세미콜론을 이스케이프 처리하는 것이 필수인 것 같습니다. 이 문제를 해결할 다른 방법이 있나요?
답변1
을(를) 삭제 중입니다 \;
. 다음을 수행하세요.
find . -type f -exec grep -il "search string" {} \; > log.txt