표준오류를 표준출력으로 돌리기

표준오류를 표준출력으로 돌리기
표준오류를 표준출력으로 전달하기

1 실습[ | ]

root@zetawiki:~# ls not-exist.txt
ls: cannot access not-exist.txt: No such file or directory
→ stderr로 출력된 오류 메시지
root@zetawiki:~# ls not-exist.txt > out.txt
ls: cannot access not-exist.txt: No such file or directory
root@zetawiki:~# cat out.txt
→ 파일로 저장해보면 보이지 않음
root@zetawiki:~# ls not-exist.txt 2> out.txt
root@zetawiki:~# cat out.txt 
ls: cannot access not-exist.txt: No such file or directory
2>를 넣어 표준오류를 파일로 전달하면 화면에는 보이지 않고 파일에만 저장됨
root@zetawiki:~# ls not-exist.txt 2>&1
ls: cannot access not-exist.txt: No such file or directory
2>&1를 넣어 표준오류를 표준출력으로 전달한 것. 화면에는 동일하게 보임
root@zetawiki:~# ls not-exist.txt > out.txt 2>&1
root@zetawiki:~# cat out.txt
ls: cannot access not-exist.txt: No such file or directory
→ 표준오류가 표준출력으로 전달되고 그것이 그대로 파일로 전달된 것. 화면에는 보이지 않고 파일로만 저장됨

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}