![stdout을 완료한 후 "find" 또는 "ls"의 결과를 파일로 파이프하려면 어떻게 해야 합니까?](https://linux55.com/image/166782/stdout%EC%9D%84%20%EC%99%84%EB%A3%8C%ED%95%9C%20%ED%9B%84%20%22find%22%20%EB%98%90%EB%8A%94%20%22ls%22%EC%9D%98%20%EA%B2%B0%EA%B3%BC%EB%A5%BC%20%ED%8C%8C%EC%9D%BC%EB%A1%9C%20%ED%8C%8C%EC%9D%B4%ED%94%84%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)
그래서 어떤 이유로 내가 다음과 같은 일을 할 때
find $PWD -type f > listoffiles.txt
현재 디렉터리에 파일 목록을 생성하고 목록에 저장하려면 해당 파일"목록 file.txt"그것은 그 자체로 어떻게든 포함되어 있는데, 이는 파이프의 STDOUT 이전에 인스턴스화되었음을 알려줍니다. 도대체 어떻게 하면 이런 일이 일어나지 않게 할 수 있을까?
답변1
MoreUtils를 사용할 수 있습니다 sponge
.
find . -type f | sponge listoffiles.txt
관련된:
답변2
find가 실행되기 전에 출력 파일이 생성됩니다. 예를 들어 다음과 같이 다른 곳에서 만들 수 있습니다.
$ find $PWD -type f > /tmp/listoffiles.txt
아니면 grep
사라집니다:
$ find $PWD -type f | grep -v "^..listoffiles.txt" > /tmp/listoffiles.txt
또는 find
무시하도록 요청하십시오.
$ find $PWD -type f -not -name listoffiles.txt > /tmp/listoffiles.txt