{"id":1264,"date":"2009-12-23T23:09:52","date_gmt":"2009-12-24T04:09:52","guid":{"rendered":"http:\/\/g33kinfo.com\/info\/?p=1264"},"modified":"2009-12-23T23:09:52","modified_gmt":"2009-12-24T04:09:52","slug":"redirection-and-pipes-on-linux","status":"publish","type":"post","link":"https:\/\/g33kinfo.com\/info\/redirection-and-pipes-on-linux\/","title":{"rendered":"Redirection and Pipes on Linux"},"content":{"rendered":"<p>Redirection:<br \/>\nWith the &gt; symbol you can forward the output of a command to a file (output redirection), with the &lt; symbol you can use a file as input for a command (input redirection).<\/p>\n<p>Pipe:<br \/>\nBy using a pipe symbol,  |   you can also redirect the output similar to the &lt; or &gt;. With a pipe, you can also combine or link the output of several commands using the output of one command as input for the next command. In contrast to the other redirection symbols &gt; and &lt;, the use of the pipe is not constrained to files.<\/p>\n<p>Examples (Redirection):<\/p>\n<p>1) To write the output of a command like ls to a file, enter<\/p>\n<pre style=\"border: 1px inset; margin: 0px; padding: 0px; overflow: auto; width: 100%; height: 25%; text-align: left;\" dir=\"ltr\">ls -l &gt; filelist.txt<\/pre>\n<p><\/p>\n<p>This creates a file named filelist.txt that contains a list of the contents\u00a0 of your current directory as generated by the ls command. However, if a file named filelist.txt already exists, this command will overwrite the existing file. To prevent this, use &gt;&gt; instead of &gt;.<br \/>\nEntering<\/p>\n<pre style=\"border: 1px inset; margin: 0px; padding: 0px; overflow: auto; width: 100%; height: 25%; text-align: left;\" dir=\"ltr\">    ls -l &gt;&gt; filelist.txt<\/pre>\n<p><\/p>\n<p>will simply appends the output of the ls command to an already existing file named filelist.txt. If the file does not exist, it is created.<\/p>\n<p>2) Redirection also works the other way round. Instead of using the standard input from the keyboard for a command, you can use a file as input:<\/p>\n<pre style=\"border: 1px inset; margin: 0px; padding: 0px; overflow: auto; width: 100%; height: 25%; text-align: left;\" dir=\"ltr\">    sort &lt; filelist.txt<\/pre>\n<p><\/p>\n<p>This will force the sort command to get its input from the contents of filelist.txt. The result is shown on the screen. Of course, you can also write the result into another file, using a combination of redirections:<\/p>\n<pre style=\"border: 1px inset; margin: 0px; padding: 0px; overflow: auto; width: 100%; height: 25%; text-align: left;\" dir=\"ltr\">    sort  &lt; filelist.txt &gt; sorted_filelist.txt<\/pre>\n<p><\/p>\n<p>Example (Pipe):<\/p>\n<p>If a command generates a lengthy output, like ls -l may do, it may be useful to pipe the output to a viewer like less to be able to scroll through the pages. To do so, enter<\/p>\n<pre style=\"border: 1px inset; margin: 0px; padding: 0px; overflow: auto; width: 100%; height: 25%; text-align: left;\" dir=\"ltr\">    ls -l | less<\/pre>\n<p><\/p>\n<p>The list of contents of the current directory is shown in less.<\/p>\n<p>The pipe is also often used in combination with the grep command in order to search for a certain string in the output of another command. For example, if you want to view a list of files in a directory which are owned by the user tux, enter<\/p>\n<pre style=\"border: 1px inset; margin: 0px; padding: 0px; overflow: auto; width: 100%; height: 25%; text-align: left;\" dir=\"ltr\">    ls -l | grep tux<\/pre>\n<p><\/p>\n<p>A longer example would be something like;<\/p>\n<pre style=\"border: 1px inset; margin: 0px; padding: 0px; overflow: auto; width: 100%; height: 25%; text-align: left;\" dir=\"ltr\">grep \"SMTP connection from\" \/var\/log\/exim_mainlog |grep \"connection count\" |awk '{print $7}' |cut -d \":\" -f 1 |cut -d \"[\" -f 2 |cut -d \"]\" -f 1 |sort -n |uniq -c | sort -n<\/pre>\n<p><\/p>\n<p>this command will search through the \/var\/log\/exim_mainlog and pull all the IPs in all the entries and line them up in an ascending order. So, you can see how the pipe symbol will take the output from one command and use it in the next and so on.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redirection: With the &gt; symbol you can forward the output of a command to a file (output redirection), with the &lt; symbol you can use a file as input for a command (input redirection). Pipe: By using a pipe symbol, | you can also redirect the output similar to the &lt; or &gt;. With a&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/g33kinfo.com\/info\/redirection-and-pipes-on-linux\/\">Read More<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-1264","post","type-post","status-publish","format-standard","hentry","category-info"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Redirection and Pipes on Linux - Linux Shtuff<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/g33kinfo.com\/info\/redirection-and-pipes-on-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Redirection and Pipes on Linux - Linux Shtuff\" \/>\n<meta property=\"og:description\" content=\"Redirection: With the &gt; symbol you can forward the output of a command to a file (output redirection), with the &lt; symbol you can use a file as input for a command (input redirection). Pipe: By using a pipe symbol, | you can also redirect the output similar to the &lt; or &gt;. With a... Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/g33kinfo.com\/info\/redirection-and-pipes-on-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"Linux Shtuff\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:author\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:published_time\" content=\"2009-12-24T04:09:52+00:00\" \/>\n<meta name=\"author\" content=\"g33kadmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/drsinger1111\" \/>\n<meta name=\"twitter:site\" content=\"@drsinger1111\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/redirection-and-pipes-on-linux\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/redirection-and-pipes-on-linux\\\/\"},\"author\":{\"name\":\"g33kadmin\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"headline\":\"Redirection and Pipes on Linux\",\"datePublished\":\"2009-12-24T04:09:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/redirection-and-pipes-on-linux\\\/\"},\"wordCount\":416,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"articleSection\":[\"General Info\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/g33kinfo.com\\\/info\\\/redirection-and-pipes-on-linux\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/redirection-and-pipes-on-linux\\\/\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/redirection-and-pipes-on-linux\\\/\",\"name\":\"Redirection and Pipes on Linux - Linux Shtuff\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\"},\"datePublished\":\"2009-12-24T04:09:52+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/redirection-and-pipes-on-linux\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/g33kinfo.com\\\/info\\\/redirection-and-pipes-on-linux\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/redirection-and-pipes-on-linux\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Redirection and Pipes on Linux\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\",\"name\":\"Linux Shtuff\",\"description\":\"Because I have CRS Syndrome...\",\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\",\"name\":\"g33kadmin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"contentUrl\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"width\":512,\"height\":512,\"caption\":\"g33kadmin\"},\"logo\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\"},\"description\":\"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\\\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....\",\"sameAs\":[\"https:\\\/\\\/thelinuxreport.com\",\"https:\\\/\\\/fb.me\\\/g33kinf0\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/drsinger1111\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Redirection and Pipes on Linux - Linux Shtuff","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/g33kinfo.com\/info\/redirection-and-pipes-on-linux\/","og_locale":"en_US","og_type":"article","og_title":"Redirection and Pipes on Linux - Linux Shtuff","og_description":"Redirection: With the &gt; symbol you can forward the output of a command to a file (output redirection), with the &lt; symbol you can use a file as input for a command (input redirection). Pipe: By using a pipe symbol, | you can also redirect the output similar to the &lt; or &gt;. With a... Read More","og_url":"https:\/\/g33kinfo.com\/info\/redirection-and-pipes-on-linux\/","og_site_name":"Linux Shtuff","article_publisher":"https:\/\/fb.me\/g33kinf0","article_author":"https:\/\/fb.me\/g33kinf0","article_published_time":"2009-12-24T04:09:52+00:00","author":"g33kadmin","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/drsinger1111","twitter_site":"@drsinger1111","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/g33kinfo.com\/info\/redirection-and-pipes-on-linux\/#article","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/redirection-and-pipes-on-linux\/"},"author":{"name":"g33kadmin","@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"headline":"Redirection and Pipes on Linux","datePublished":"2009-12-24T04:09:52+00:00","mainEntityOfPage":{"@id":"https:\/\/g33kinfo.com\/info\/redirection-and-pipes-on-linux\/"},"wordCount":416,"commentCount":0,"publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"articleSection":["General Info"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/g33kinfo.com\/info\/redirection-and-pipes-on-linux\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/g33kinfo.com\/info\/redirection-and-pipes-on-linux\/","url":"https:\/\/g33kinfo.com\/info\/redirection-and-pipes-on-linux\/","name":"Redirection and Pipes on Linux - Linux Shtuff","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/#website"},"datePublished":"2009-12-24T04:09:52+00:00","breadcrumb":{"@id":"https:\/\/g33kinfo.com\/info\/redirection-and-pipes-on-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/g33kinfo.com\/info\/redirection-and-pipes-on-linux\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/g33kinfo.com\/info\/redirection-and-pipes-on-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/g33kinfo.com\/info\/"},{"@type":"ListItem","position":2,"name":"Redirection and Pipes on Linux"}]},{"@type":"WebSite","@id":"https:\/\/g33kinfo.com\/info\/#website","url":"https:\/\/g33kinfo.com\/info\/","name":"Linux Shtuff","description":"Because I have CRS Syndrome...","publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/g33kinfo.com\/info\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547","name":"g33kadmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","url":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","contentUrl":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","width":512,"height":512,"caption":"g33kadmin"},"logo":{"@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif"},"description":"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....","sameAs":["https:\/\/thelinuxreport.com","https:\/\/fb.me\/g33kinf0","https:\/\/x.com\/https:\/\/twitter.com\/drsinger1111"]}]}},"_links":{"self":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/1264","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/comments?post=1264"}],"version-history":[{"count":0,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/1264\/revisions"}],"wp:attachment":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/media?parent=1264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/categories?post=1264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/tags?post=1264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}