{"componentChunkName":"component---src-templates-blog-post-js","path":"/linux/생활코딩-리눅스-강좌(IO-Redirection)/","result":{"data":{"site":{"siteMetadata":{"title":"Study Log","author":"[HongDongUk]","siteUrl":"https://donguk.netlify.com","comment":{"disqusShortName":"","utterances":"doonguk/doonguk.github.io"},"sponsor":{"buyMeACoffeeId":"doonguk"}}},"markdownRemark":{"id":"06744ca2-9266-5f87-a807-df6178306018","excerpt":"IO Redirection IO Redirection ( Input Ouput Redirection ) : input 과 output의 방향을 바꾼다 UNIX 계열의 시스템은 Standard Input( Command ) 이 주어지면 Unix process를 거쳐 Standard output을 내보냄 ls -l 1> result.txt : ls -l 의 결 과물을 result.txt에 저장. Standard ouput의 출력 방향을 바꿔주는 방법 ( > 가 수행,…","html":"<h2 id=\"io-redirection\" style=\"position:relative;\"><a href=\"#io-redirection\" aria-label=\"io redirection permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>IO Redirection</h2>\n<img width=\"506\" alt=\"&#xC2A4;&#xD06C;&#xB9B0;&#xC0F7; 2019-11-09 &#xC624;&#xC804; 12 26 33\" src=\"https://user-images.githubusercontent.com/39187116/68488114-b5134180-0287-11ea-8d1b-62849422f230.png\">\n<ul>\n<li>\n<p>IO Redirection ( Input Ouput Redirection ) : input 과 output의 방향을 바꾼다</p>\n<ul>\n<li>UNIX 계열의 시스템은 Standard Input( Command ) 이 주어지면 Unix process를 거쳐 Standard output을 내보냄</li>\n<li><code>ls -l 1> result.txt</code> : ls -l 의 결 과물을 result.txt에 저장. Standard ouput의 출력 방향을 바꿔주는 방법 ( <code>></code> 가 수행, 1은 생략 가능하다.  )</li>\n<li>Standard error은 Standard Input이 process에서 오류가 발생하면 생김 </li>\n<li>Standard error은 redirection 할 수 없다. 하지만 <code>2> </code> 를 사용 한다면 error도 redirection 가능하다.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token comment\">#현재 디렉토리에 test.txt가 없을때</span>\n$ <span class=\"token function\">rm</span> test.txt // 오류 발생\n$ <span class=\"token function\">rm</span> test.txt <span class=\"token operator\">></span> result.txt //오류가 result.txt에 저장되지 않음 <span class=\"token punctuation\">(</span> Standard error를 redirection <span class=\"token punctuation\">)</span>\n$ <span class=\"token function\">rm</span> test.txt <span class=\"token operator\">></span> result.txt <span class=\"token operator\"><span class=\"token file-descriptor important\">2</span>></span> result2.txt // result2.txt에 오류가 저장됌</code></pre></div>\n<ul>\n<li><code>cat </code> : 파일 읽기 </li>\n<li><code>cat &#x3C; hello.txt </code> 명령어가 Standard Input으로 파일을 받는다면 파일의 내용을 Standard Output으로 내보낸다  &#x3C; 는 input을 redirection 한 것이다.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">$ <span class=\"token function\">head</span> -n1 linux.txt // -n1 은 Command line Arguments, linux.txt는 Standard Input\n$ <span class=\"token function\">head</span> -n1 <span class=\"token operator\">&lt;</span> linux.txt //위와 같음\n$ <span class=\"token function\">head</span> -n1 <span class=\"token operator\">&lt;</span> linux.txt <span class=\"token operator\">></span> result.txt //input redirection과 output redirection 모두 일어남\n//linux.txt 의 첫번째 행을 result.txt에 저장</code></pre></div>\n</li>\n<li>input 과 output 흘러 나가는 이런 형태를 <strong>IO stream</strong> 이라고 한다.</li>\n</ul>\n<h2 id=\"추가적인-기능\" style=\"position:relative;\"><a href=\"#%EC%B6%94%EA%B0%80%EC%A0%81%EC%9D%B8-%EA%B8%B0%EB%8A%A5\" aria-label=\"추가적인 기능 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>추가적인 기능</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">$ <span class=\"token function\">ls</span> -al <span class=\"token operator\">></span> result.txt // Standard output 을 result.txt에 저장\n$ <span class=\"token function\">ls</span> -al <span class=\"token operator\">></span> result.txt // 결과가 result.txt에 덮어 씌워짐\n$ <span class=\"token function\">ls</span> -al <span class=\"token operator\">>></span> result.txt // 결과가 result.txt에 누적됌 <span class=\"token punctuation\">(</span> append <span class=\"token punctuation\">)</span>\n\n$ <span class=\"token function\">ls</span> -al <span class=\"token operator\">></span> /dev/null //실행결과를 /dev/null로 redirection, 화면에도 파일에도 출력x, 쓰레기통 같은곳임</code></pre></div>","frontmatter":{"title":"생활코딩 리눅스 강좌(IO Redirection)","date":"November 09, 2019"}}},"pageContext":{"slug":"/linux/생활코딩-리눅스-강좌(IO-Redirection)/","previous":{"fields":{"slug":"/linux/생활코딩-리눅스-강좌( 기초-2 )/"},"frontmatter":{"title":"생활코딩 리눅스 강좌(기초-2)","category":"linux"}},"next":{"fields":{"slug":"/linux/생활코딩-리눅스-강좌(shell)/"},"frontmatter":{"title":"생활코딩 리눅스 강좌(Shell)","category":"linux"}}}},"staticQueryHashes":["3128451518","96099027"]}