Linux2010. 2. 22. 13:21
리다이렉션은, 데이터의 흐름(?)을 다른 곳으로 돌려주는 것을 의미한다.

fd = 0 은 stdin(입력)
fd = 1 은 stdout(표준출력)
fd = 2 는 stderr(표준에러출력)
으로 설정되는데, 이러한 출력을 다른 곳으로 돌려주는 역활을 한다.

에러만 파일에 저장하려면
make 2> err.log

일반메시지만 저장하려면
make > err.log

둘다 저장하려면
make > err.log 2>&1

으로 하면된다.

make 2>&1 err.log
라고 하면 에러가나니, 반드시 파일명과 함께 리다이렉션시킬 방향을 별도로 적어 주어야 한다.

       Before  a command is executed, its input and output may be redirected using a special notation interpreted by the
       shell.  Redirection may also be used to open and close files for the current shell  execution  environment.   The
       following  redirection  operators may precede or appear anywhere within a simple command or may follow a command.
       Redirections are processed in the order they appear, from left to right.

       In the following descriptions, if the file descriptor number is omitted, and the first character of the  redirec-
       tion  operator is <, the redirection refers to the standard input (file descriptor 0).  If the first character of
       the redirection operator is >, the redirection refers to the standard output (file descriptor 1).

       The word following the redirection operator in the following descriptions, unless otherwise noted,  is  subjected
       to  brace  expansion,  tilde  expansion,  parameter  expansion, command substitution, arithmetic expansion, quote
       removal, pathname expansion, and word splitting.  If it expands to more than one word, bash reports an error.

       Note that the order of redirections is significant.  For example, the command

              ls > dirlist 2>&1

       directs both standard output and standard error to the file dirlist, while the command

              ls 2>&1 > dirlist

       directs only the standard output to file dirlist, because the standard error was duplicated  as  standard  output
       before the standard output was redirected to dirlist.

[링크 :]

'Linux' 카테고리의 다른 글

diff의 -u 옵션 출력 내용 읽기 how read diff unified format?  (0) 2010.02.23
configure 관련 문서 모음  (0) 2010.02.23
리눅스 드라이버 / 모듈  (0) 2010.02.19
bash shell - TMOUT 환경변수  (0) 2010.02.18
chmod(3)  (0) 2010.02.18
Posted by 구차니