Linux 명령어: tee, nl 사용법
Linux tee, nl 명령어 사용법입니다. tee -a, sudo tee, 명령 출력 저장, nl -ba, -v, -i, -w 옵션과 pipe 조합을 정리했습니다.
Linux 명령어: tee, nl 사용법
tee는 표준 입력을 화면에 출력하면서 동시에 파일에 저장한다. nl은 텍스트에 줄 번호를 붙여 출력한다. 두 명령은 pipe와 함께 쓰면 로그 저장, 설정 파일 생성, 출력 검토에 유용하다.
tee 기본 사용
mkdir -p ~/tee-nl-lab
cd ~/tee-nl-lab
echo "first line" | tee output.txt
cat output.txt파일에 추가: tee -a
echo "second line" | tee -a output.txt
echo "third line" | tee -a output.txt
cat output.txtsudo 권한 파일에 쓰기
redirection은 shell이 먼저 처리하므로 sudo echo ... > file 형태는 실패할 수 있다. 이때 sudo tee를 사용한다.
echo "192.168.10.101 server01.lab.local server01" | sudo tee -a /etc/hosts명령 출력 저장과 화면 출력 동시 처리
ip -br addr | tee network-summary.txt
df -hT | tee disk-summary.txtnl 기본 사용
printf "alpha\nbeta\n\ngamma\n" > sample.txt
nl sample.txt빈 줄까지 번호 붙이기
nl -ba sample.txt시작 번호와 증가값 조절
nl -v 100 -i 10 sample.txt번호 폭 조절
nl -w 3 -s ': ' sample.txttee와 nl 조합
journalctl -n 20 --no-pager | nl -ba | tee recent-journal-numbered.txt마무리
tee는 화면 출력과 파일 저장을 동시에 할 때, nl은 텍스트에 줄 번호를 붙여 검토할 때 유용하다. 특히 sudo tee는 root 권한 파일에 pipe 결과를 안전하게 기록할 때 자주 사용한다.