Linux/RedHat, CentOS, ubuntu

[리눅스 명령어] tee 표준입력으로부터 표준출력과 파일로 저장

Pydole 2019. 11. 25. 13:20

 

어떤 명령어의 결과를 표준출력과 파일 저장을 같이 하고 싶을 때, 사용하는 명령어의 결과를 로깅파일로 만들 때, 유용하다.

 


 

 

실행결과를 표준출력과 파일로 저장

 

$ echo 'this is tee command' | tee tee.log
this is tee command

 

$ cat tee.log
this is tee command

 

 

 

 

 

실행결과를 표준출력과 파일로 저장. ( -a 옵션을 사용하여 append(추가하기))

 

 

$ echo 'this is tee command1' | tee -a tee.log
this is tee command1

 

 

$ echo 'this is tee command2' | tee -a tee.log
this is tee command2

 

 

$ cat tee.log
this is tee command1
this is tee command2

 

 

 

 

 

활용) 일단위 날짜형식의 로깅파일로 만들기

 

#/bin/bash

echo 'this is tee command1' | tee -a `date +%y%m%d`.log
echo 'this is tee command2' | tee -a `date +%y%m%d`.log

--------------------------------------------------------

$ ./df.sh
this is tee command1
this is tee command2


$ cat 191125.log
this is tee command1
this is tee command2