1. tee 명령어
- standard input에서 문자열을 읽어서 standard output과 파일에 문자열을 씀
2. 사용법
(1) echo 명령어와 사용
- test.txt에 기존 내용이 있다면 모두 삭제되고 "hello"만 저장
$ echo "hello" | tee test.txt
(2) cat 명령어와 사용
- 파일을 읽어서 새로운 파일로 내용 저장
$ cat test.txt | tee test2.txt
(3) echo 명령어로 기존 파일 뒤에 내용 추가
$ echo "world" | tee -a test.txt
(4) /dev/null을 이용하여 터미널에는 표기되지 않게 사용
$ echo "hello" | tee -a test.txt /dev/null
3. 심화
$ echo "hello" >> test.txt
$ echo "hello" | tee -a test.txt
- 위 두 명령어는 같은 결과를 보임
- 일반사용자 계정일 경우 sudo echo와 같이 사용할 경우 root 권한 파일에는 Permission denied로 정상동작하지 않음
- 위와 같은 경우 echo를 sudo tee로 받아서 실행하면 정상적으로 작동
- 쉘 스크립트에서 root 권한으로 특정파일을 쓰거나 append 할 때 주로 사용한다고 함.
참고) https://www.lesstif.com/lpt/linux-tee-89556049.html
'Linux' 카테고리의 다른 글
리눅스 bash 문자열 변수 조작 (자르기, 삭제, 치환) (0) | 2021.10.26 |
---|---|
[sed] 파일 내 문자열 변경1 (0) | 2021.10.26 |
[CentOS7] kubernetes master node - haproxy, keepalived (0) | 2021.06.25 |
sshpass로 한 번에 key 복사, 로그인없이 사용 (0) | 2021.06.02 |
[CentOS] yum repository 구성 (0) | 2021.05.27 |