![Unix, 명령을 기반으로 파일 생성 [중복]](https://linux55.com/image/85643/Unix%2C%20%EB%AA%85%EB%A0%B9%EC%9D%84%20%EA%B8%B0%EB%B0%98%EC%9C%BC%EB%A1%9C%20%ED%8C%8C%EC%9D%BC%20%EC%83%9D%EC%84%B1%20%5B%EC%A4%91%EB%B3%B5%5D.png)
명령이 있지만 결과를 열 수 있는 .txt 파일에 저장하고 싶습니다. 결과를 텍스트 파일에 넣을 수 있도록 명령을 어떻게 변경할 수 있습니까? 이 .txt 파일을 로컬 데스크톱으로 전송할 계획입니다.
my command | grep stackoverflow
내가 시도한 것: echo my command | grep stackoverflow > ex.txt
하지만 .txt 파일에는 아무것도 나타나지 않습니다.
감사해요.
답변1
글쎄, 기본적으로 출력 리디렉션을 사용하여
my command|grep stackoverflow > file #writes output to <file>
my command|grep stackoverflow >> file #appends <file> with output
my command|grep stackoverflow|tee file #writes output to <file> and still prints to stdout
my command|grep stackoverflow|tee -a file #appends <file> with output and still prints to stdout
파이프는 stdout의 모든 것을 가져와 후속 명령에 대한 입력으로 사용합니다. 그래서:
echo "this is a text" # prints "this is a text"
ls # prints the contents of the current directory
이제 grep은 입력에서 일치하는 정규식을 찾으려고 시도합니다.
echo "my command" | grep stackoverflow #will find no matching line.
echo "my command" | grep command #will find a matching line.
"my command"는 "my command"라는 메시지가 아니라 명령을 의미하는 것 같습니다.