서버/리눅스
tee logging
iiliiiili
2021. 12. 14. 22:38
https://stackoverflow.com/questions/11337041/force-line-buffering-of-stdout-in-a-pipeline
Force line-buffering of stdout in a pipeline
Usually, stdout is line-buffered. In other words, as long as your printf argument ends with a newline, you can expect the line to be printed instantly. This does not appear to hold when using a pip...
stackoverflow.com
1. tee 명령어
입력한 내용을 화면에 출력하는 동시에 파일에 저장하도록 하는 명령어
2. 사용법
tee [옵션] 파일명
-a, --append : 기존의 파일에 덮어 쓰지 않고 추가한다.
-i, --ignore-interrupts : 인터럽트 시그널을 무시한다.
3. 사용예
# cat 1.txt
Ccc
Aaa
Bbb
# cat 1.txt | sort | tee 2.txt
Aaa
Bbb
Ccc
# cat 2.txt
Aaa
Bbb
Ccc
4. Shell 에서 파일 생성하기
# tee test.txt << EOF
> 1
> 2
> 3
> End!
> EOF
1
2
3
End!
$ cat test.txt
1
2
3
End!