{"id":1872,"date":"2020-09-18T16:55:00","date_gmt":"2020-09-18T13:55:00","guid":{"rendered":"https:\/\/www.virtono.com\/community\/?p=1872"},"modified":"2020-09-16T15:12:28","modified_gmt":"2020-09-16T12:12:28","slug":"using-redirection-to-read-and-write-data-from-anywhere-in-the-linux-terminal","status":"publish","type":"post","link":"https:\/\/www.virtono.com\/community\/knowledgebase\/using-redirection-to-read-and-write-data-from-anywhere-in-the-linux-terminal\/","title":{"rendered":"Using redirection to Read and Write data from anywhere in the Linux terminal"},"content":{"rendered":"\n<p>Redirection of results and input is an all-natural function of any development or scripting language. Technically, it happens whenever you connect to a computer inherently. Input gets to go through from stdin (standard input, generally your keyboard or mouse), the output would go to stdout (standard output, a text message or data stream), and errors get delivered to stderr. Knowing that these data streams can be found enables you to regulate where information goes if you are using a shell, such as for example Zsh or Bash.<\/p>\n\n\n\n<p>You should get your feet wet by using these tutorials and getting to know linux better on a Cloud VPS from <a href=\"https:\/\/www.virtono.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p>Standard in, standard out, and standard error exist as filesystem locations on Linux. You can see them in&nbsp;<code>\/dev<\/code>:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p><strong>$&nbsp;ls&nbsp;\/dev\/std*<\/strong><br><strong>\/dev\/stderr@&nbsp;&nbsp;\/dev\/stdin@&nbsp;&nbsp;\/dev\/stdout@<\/strong><gwmw style=\"display:none;\"><\/gwmw><\/p><\/blockquote>\n\n\n\n<p>You can&#8217;t carry out much with them directly, but it&#8217;s sometimes beneficial to think about them as meta-locations where one can send data.<\/p>\n\n\n\n<p>The fundamentals of redirection are simple: use some number of &gt; characters to redirect output, plus some true number of &lt; characters to redirect input.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_73 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.virtono.com\/community\/knowledgebase\/using-redirection-to-read-and-write-data-from-anywhere-in-the-linux-terminal\/#Redirecting_output\" title=\"Redirecting output\">Redirecting output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.virtono.com\/community\/knowledgebase\/using-redirection-to-read-and-write-data-from-anywhere-in-the-linux-terminal\/#Redirecting_input\" title=\"Redirecting input\">Redirecting input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.virtono.com\/community\/knowledgebase\/using-redirection-to-read-and-write-data-from-anywhere-in-the-linux-terminal\/#Redirecting_error_messages\" title=\"Redirecting error messages\">Redirecting error messages<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.virtono.com\/community\/knowledgebase\/using-redirection-to-read-and-write-data-from-anywhere-in-the-linux-terminal\/#Redirecting_error_messages-2\" title=\"Redirecting error messages\">Redirecting error messages<\/a><\/li><\/ul><\/nav><\/div>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Redirecting_output\"><\/span>Redirecting output<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>To write the output of the&nbsp;ls command to a file:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p><code><em>$&nbsp;<\/em><strong>ls<\/strong>&nbsp;<strong>&gt;<\/strong>&nbsp;list.txt<\/code> <gwmw style=\"display:none;\"><gwmw style=\"display:none;\"><gwmw style=\"display:none;\"><\/gwmw><\/gwmw><\/gwmw><\/p><\/blockquote>\n\n\n\n<p>You don&#8217;t see the output of ls as you normally would because the output is going to be written to the list.txt file rather than your screen. This is therefore versatile, in fact, that you can also use it to copy the contents of one file to another. It doesn&#8217;t have to be a text file, as well. You can use redirection for binary data:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$\u00a0cat\u00a0image.png\u00a0>\u00a0picture.png<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Redirecting_input\"><\/span>Redirecting input<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>It is possible to redirect input &#8220;into&#8221; a command, too. It could be useful, however, when a list is expected by a command of arguments, and you also have those arguments in a document and want to quickly &#8220;copy and paste&#8221; them from the document into the terminal (except you do not really need to copy and paste): That is probably less useful than redirecting result because many commands already are hard-coded to consider input from arguments you provide.<\/p>\n\n\n\n<p>$ sudo dnf install $(&lt;package.list&gt;)<\/p>\n\n\n\n<p>Common uses of input redirection are the here-document (or just here-doc for short) and here-string techniques. This input method redirects a block of text into the standard input stream, up to a special end-of-file marker (most people use EOF, but it can be any string you expect to be unique). Try typing this (up to the second instance of EOF) into a terminal:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>$&nbsp;echo&nbsp;&lt;&lt;&nbsp;EOF<br>&gt;&nbsp;foo<br>&gt;&nbsp;bar<br>&gt;&nbsp;baz<br>&gt;&nbsp;EOF<\/p><\/blockquote>\n\n\n\n<p>The expected result:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>foo <\/p><p>bar <\/p><p>baz<\/p><\/blockquote>\n\n\n\n<p>A here-doc is a common technique utilized by Bash scripters to dump several lines of text into a document or onto the display. So long as you do not forget to end the clause together with your end-of-file marker, it&#8217;s a highly effective means of avoiding unwieldy lists of echo or printf statements.<\/p>\n\n\n\n<p>A here-string is comparable to a here-doc, nonetheless it consists of just one single string (or many strings disguised as an individual string with quotation marks):<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>$&nbsp;cat&nbsp;&lt;&lt;&lt;&nbsp;&#8220;foo bar baz&#8221;<br>foo bar baz<\/p><\/blockquote>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Redirecting_error_messages\"><\/span>Redirecting error messages<gwmw style=\"display:none;\"><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Redirecting_error_messages-2\"><\/span>Redirecting error messages<gwmw style=\"display:none;\"><\/gwmw><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Error messages go to a stream called&nbsp;<code>stderr<\/code>, designated as&nbsp;<code>2&gt;<\/code>&nbsp;for the purposes of redirection. This command directs error messages to a file called&nbsp;<code>output.log<\/code>:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>$&nbsp;ls&nbsp;\/nope&nbsp;2&gt;&nbsp;output.log<gwmw style=\"display:none;\"><gwmw style=\"display:none;\"><\/gwmw><gwmw style=\"display:none;\"><\/gwmw><\/gwmw><\/p><\/blockquote>\n\n\n\n<p><gwmw style=\"display:none;\"><\/gwmw><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redirection of results and input is an all-natural function of any development or scripting language. Technically, it happens whenever you connect to a computer inherently. Input gets to go through from stdin (standard input, generally your keyboard or mouse), the output would go to stdout (standard output, a text message<\/p>\n","protected":false},"author":4,"featured_media":1896,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5],"tags":[],"class_list":["post-1872","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-knowledgebase"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2020\/09\/af2cde9k5712330xy457.png?fit=1000%2C420&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7ISfL-uc","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":235,"url":"https:\/\/www.virtono.com\/community\/knowledgebase\/lamp-technology\/","url_meta":{"origin":1872,"position":0},"title":"LAMP TECHNOLOGY","author":"Daniel Draga","date":"July 30, 2016","format":false,"excerpt":"LAMP STANDS FOR: L:Linux A:Apache M:MySQL P:PHP What is LAMP? LAMP is a shorthand term for a web application platform consisting of Linux, Apache, MySQL and one of Perl or PHP. Lamp is an\u00a0 OPENSOURCE Together, these open source tools provide a world-class platform for deploying web applications TECHNOLOGIES USED\u2026","rel":"","context":"In &quot;Knowledgebase&quot;","block_context":{"text":"Knowledgebase","link":"https:\/\/www.virtono.com\/community\/category\/knowledgebase\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2016\/07\/ic-1.png?fit=1200%2C750&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2016\/07\/ic-1.png?fit=1200%2C750&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2016\/07\/ic-1.png?fit=1200%2C750&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2016\/07\/ic-1.png?fit=1200%2C750&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2016\/07\/ic-1.png?fit=1200%2C750&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":2136,"url":"https:\/\/www.virtono.com\/community\/knowledgebase\/linux-encryption-how-to-secure-your-data\/","url_meta":{"origin":1872,"position":1},"title":"Linux encryption: How to secure your data","author":"Shreyash Sharma","date":"December 12, 2020","format":false,"excerpt":"Sales figures, strategy papers, payrolls and private records, pictures, account data, and passwords do not belong in the wrong hands. This article shows where encryption is necessary and how it is best implemented. Encryption is technically not a problem at all. There are several reliable methods under Linux for protecting\u2026","rel":"","context":"In &quot;Knowledgebase&quot;","block_context":{"text":"Knowledgebase","link":"https:\/\/www.virtono.com\/community\/category\/knowledgebase\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2020\/12\/linux-encrypting-tools.png?fit=560%2C315&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2020\/12\/linux-encrypting-tools.png?fit=560%2C315&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2020\/12\/linux-encrypting-tools.png?fit=560%2C315&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":1795,"url":"https:\/\/www.virtono.com\/community\/knowledgebase\/10-linux-basic-commands-every-user-should-know\/","url_meta":{"origin":1872,"position":2},"title":"10 Linux Basic Commands Every User Should Know","author":"Shreyash Sharma","date":"July 31, 2020","format":false,"excerpt":"Linux can be daunting to some, especially if you have seen people working only through the terminal. Trust me, its not as complicated as it seems neither is it that hard to learn. The only issue is manufacturers do not Linux with their systems. What is Linux? The entire family\u2026","rel":"","context":"In &quot;Knowledgebase&quot;","block_context":{"text":"Knowledgebase","link":"https:\/\/www.virtono.com\/community\/category\/knowledgebase\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2020\/07\/7rQQixjPnrQv.png?fit=640%2C363&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2020\/07\/7rQQixjPnrQv.png?fit=640%2C363&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2020\/07\/7rQQixjPnrQv.png?fit=640%2C363&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3225,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-find-the-largest-files-in-linux\/","url_meta":{"origin":1872,"position":3},"title":"How to find the largest files in Linux","author":"George B.","date":"April 12, 2023","format":false,"excerpt":"When you have a server with 1TB of disk space and your storage is 80% full, it is important to find out which files(largest files) are taking up the most space on your system. This can be done by identifying the biggest files on your system and deleting or moving\u2026","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/www.virtono.com\/community\/category\/tutorial-how-to\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/04\/How-to-find-largest-files-linux.png?fit=600%2C330&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/04\/How-to-find-largest-files-linux.png?fit=600%2C330&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/04\/How-to-find-largest-files-linux.png?fit=600%2C330&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":2144,"url":"https:\/\/www.virtono.com\/community\/knowledgebase\/the-best-linux-distributions-for-old-hardware\/","url_meta":{"origin":1872,"position":4},"title":"The best Linux distributions for old hardware","author":"Shreyash Sharma","date":"December 15, 2020","format":false,"excerpt":"There is no hardware for which a working Linux is not available.\u00a0Finding the right role for old hardware and the right board and system for a planned role is still complicated. For a practical presentation, almost each of the following aspects would have deserved its own workshop.\u00a0This entry-level contribution to\u2026","rel":"","context":"In &quot;Knowledgebase&quot;","block_context":{"text":"Knowledgebase","link":"https:\/\/www.virtono.com\/community\/category\/knowledgebase\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2020\/12\/Which-Distro1.png?fit=705%2C273&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2020\/12\/Which-Distro1.png?fit=705%2C273&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2020\/12\/Which-Distro1.png?fit=705%2C273&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2020\/12\/Which-Distro1.png?fit=705%2C273&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":2154,"url":"https:\/\/www.virtono.com\/community\/internet-and-technology-news\/linux-mint-desktop-cinnamon-4-8-is-ready\/","url_meta":{"origin":1872,"position":5},"title":"Linux Mint Desktop Cinnamon 4.8 is ready","author":"Shreyash Sharma","date":"December 10, 2020","format":false,"excerpt":"The Linux Mint team has completed the development of Cinnamon 4.8 and provides the standard Mint desktop environment in a new, stable version.\u00a0The desktop will have its debut with Linux Mint 20.1 \u00bbUlyssa\u00ab, which is expected to be released in December. Favorites A function that has long been requested by\u2026","rel":"","context":"In &quot;IT News&quot;","block_context":{"text":"IT News","link":"https:\/\/www.virtono.com\/community\/category\/internet-and-technology-news\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2020\/12\/cinnamon-1.png?fit=1200%2C750&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2020\/12\/cinnamon-1.png?fit=1200%2C750&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2020\/12\/cinnamon-1.png?fit=1200%2C750&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2020\/12\/cinnamon-1.png?fit=1200%2C750&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2020\/12\/cinnamon-1.png?fit=1200%2C750&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts\/1872","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/comments?post=1872"}],"version-history":[{"count":6,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts\/1872\/revisions"}],"predecessor-version":[{"id":2012,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts\/1872\/revisions\/2012"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/media\/1896"}],"wp:attachment":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/media?parent=1872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/categories?post=1872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/tags?post=1872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}