grep을 파일로 리디렉션이 작동하지 않습니다.

grep을 파일로 리디렉션이 작동하지 않습니다.

다음 명령으로 재귀 grep을 수행하고 있습니다.

grep -r "load" . > tmp.txt

그러나 Enter 키를 누르면 명령이 실행되지 않고 bash가 추가 입력을 기다리고 있습니다. 내 OS는 Ubuntu 12.04입니다.

다음 두 가지 답변을 확인했지만 문제를 해결할 수 없습니다.

grep이 리디렉션과 함께 작동하지 않는 이유는 무엇입니까?

tailf 및 grep의 출력을 파일로 어떻게 리디렉션합니까?

답변1

Ubuntu 12.04도 사용하는데 다음 오류가 발생합니다.

$ grep -r 'test' . > tmp.txt
grep: input file `./tmp.txt' is also the output

리디렉션이 먼저 확장되므로 실행되기 tmp.txt전에 현재 디렉터리에 생성되므로 grep오류가 발생합니다.

tmp.txt와 같은 다른 경로로 변경하면 /tmp/tmp.txt정상적으로 작동합니다.

grep버전:

$ grep --version
grep (GNU grep) 2.10
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.

관련 정보