source

stdout과 stderr을 모두 파일로 리디렉션하는 방법

ittop 2023. 4. 17. 22:30
반응형

stdout과 stderr을 모두 파일로 리디렉션하는 방법

명령 실행을 위한 로그 파일을 생성하는 bash 스크립트를 실행하고 있습니다.

다음을 사용합니다.

Command1 >> log_file
Command2 >> log_file

이것은, 단말기에 표시되는 표준 에러가 아니고, 표준 출력만을 송신합니다.

같은 파일에 로그하는 경우:

command1 >> log_file 2>&1

다른 파일을 원하는 경우:

command1 >> log_file 2>> err_file

양쪽을 리다이렉트 하는 가장 간단한 구문은 다음과 같습니다.

command &> logfile

덮어쓰기 대신 파일에 추가할 경우:

command &>> logfile

2 > & 1 : 이렇게 할 수 있습니다.

 command > file 2>&1

용도:

command >>log_file 2>>log_file

사용하세요command 2>file여기서2stderr의 파일 기술자를 나타냅니다.를 사용할 수도 있습니다.1대신2stdout이 '파일'로 리다이렉트되도록 합니다.

언급URL : https://stackoverflow.com/questions/7526971/how-to-redirect-both-stdout-and-stderr-to-a-file

반응형