{"id":2584,"date":"2018-01-12T19:55:13","date_gmt":"2018-01-12T16:55:13","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-yes-command\/"},"modified":"2018-01-12T19:55:13","modified_gmt":"2018-01-12T16:55:13","slug":"linux-yes-command-tutorial-for-beginners-with-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-yes-command-tutorial-for-beginners-with-examples\/","title":{"rendered":"Linux yes Command Tutorial for Beginners (with Examples)"},"content":{"rendered":"<p>Most of the Linux commands you encounter do not depend on other operations for users to unlock their full potential, but there exists a small subset of command line tool which you can say are useless when used independently, but become a must-have or must-know when used with other command line operations. One such tool is <em><strong>yes<\/strong><\/em>, and in this tutorial, we will discuss this command with some easy to understand examples.<\/p>\n<p>But before we do that, it&#8217;s worth mentioning that all examples provided in this tutorial have been tested on Ubuntu 16.04 LTS.<\/p>\n<h2 id=\"linux-yes-command\">Linux yes command<\/h2>\n<p>The yes command in Linux outputs a string repeatedly until killed. Following is the syntax of the command:<\/p>\n<p class=\"command\">yes [STRING]&#8230;<br \/>yes OPTION<\/p>\n<p>And here&#8217;s what the man page says about this tool:<\/p>\n<pre>Repeatedly output a line with all specified STRING(s), or 'y'.<\/pre>\n<p>The following Q&amp;A-type examples should give you a better idea about the usage of yes.<\/p>\n<h2 id=\"q-how-yes-command-works\">Q1. How yes command works?<\/h2>\n<p>As the man page says, the yes command produces\u00a0continuous output &#8211; &#8216;y&#8217; by default, or any other string if specified by user. Here&#8217;s a screenshot that shows the yes command in action:<\/p>\n<p><a class=\"fancybox\" id=\"img-yes-def-output\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/yes-def-output.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/01\/linux-yes-command-tutorial-for-beginners-with-examples.png\" alt=\"How yes command works\" width=\"213\" height=\"135\" title=\"\"><\/a><\/p>\n<p><em>I could only capture the last part of the output as the output frequency was so fast, but the screenshot should give you a good idea about what kind of output the tool produces.<\/em><\/p>\n<p>You can also provide a custom string for the yes command to use in output. For example:<\/p>\n<p class=\"command\">yes HTF<\/p>\n<p><a class=\"fancybox\" id=\"img-yes-custom-string\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/yes-custom-string.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/01\/linux-yes-command-tutorial-for-beginners-with-examples-1.png\" alt=\"Repeat word with yes command\" width=\"204\" height=\"152\" title=\"\"><\/a><\/p>\n<h2 id=\"q-where-yes-command-helps-the-user\">Q2. Where yes command helps the user?<\/h2>\n<p>That&#8217;s a valid question. Reason being, from what yes does, it&#8217;s difficult to imagine the usefulness of the tool. But you&#8217;ll be surprised to know that yes can not only save your time, but also automate some mundane tasks.<\/p>\n<p>For example, consider the following scenario:<\/p>\n<p><a class=\"fancybox\" id=\"img-rm-ri-output\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/rm-ri-output.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/01\/linux-yes-command-tutorial-for-beginners-with-examples-2.png\" alt=\"Where yes command helps the user\" width=\"462\" height=\"188\" title=\"\"><\/a><\/p>\n<p>You can see that user has to type &#8216;y&#8217; for each query. It&#8217;s in situation like these where yes can help. For the above scenario specifically, you can use yes in the following way:<\/p>\n<p class=\"command\">yes | rm -ri test<\/p>\n<p><a class=\"fancybox\" id=\"img-yes-in-action\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/yes-in-action.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/01\/linux-yes-command-tutorial-for-beginners-with-examples-3.png\" alt=\"yes command in action\" width=\"500\" height=\"33\" title=\"\"><\/a><\/p>\n<p>So the command made sure user doesn&#8217;t have to write &#8216;y&#8217; each time when rm asked for it. Of course, one would argue that we could have simply removed the &#8216;-i&#8217; option from the rm command. That&#8217;s right, I took this example as it&#8217;s simple enough to make people understand the situations in which yes can be helpful.<\/p>\n<p>Another &#8211; and probably more\u00a0relevant &#8211; scenario would be when you&#8217;re using the <em>fsck<\/em> command, and don&#8217;t want to enter &#8216;y&#8217; each time system asks your permission before fixing errors.<\/p>\n<h2 id=\"q-is-there-any-use-of-yes-when-its-used-alone\">Q3. Is there any use of yes when it&#8217;s used alone?<\/h2>\n<p>Yes, there&#8217;s at-least one use: to tell how well a computer system handles high amount of loads. Reason being, the tool utilizes 100% processor for systems that have a single processor. In case you want to apply this test on a system with multiple processors, you need to run a yes process for each processor.<\/p>\n<h2 id=\"q-what-command-line-options-yes-offers\">Q4. What command line options yes offers?<\/h2>\n<p>The tool only offers generic command line options: &#8211;help and &#8211;version. As the names suggests. the former displays help information related to the command, while the latter one outputs version related information.<\/p>\n<p><a class=\"fancybox\" id=\"img-yes-help-version1\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/yes-help-version1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/01\/linux-yes-command-tutorial-for-beginners-with-examples-4.png\" alt=\"What command line options yes offers\" width=\"500\" height=\"229\" title=\"\"><\/a><\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>So now you&#8217;d agree that there could be several scenarios where the yes command would be of help. There are no command line options unique to yes, so effectively, there&#8217;s no learning curve associated with the tool. Just in case you need, here&#8217;s the command&#8217;s <a href=\"https:\/\/linux.die.net\/man\/1\/yes\" target=\"_blank\" rel=\"noopener noreferrer\">man page<\/a>.<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Most of the Linux commands you encounter do not depend on other operations for users to unlock their full potential, but there exists a small subset of command line tool which you can say are useless when used independently, but become a must-have or must-know when used with other command line operations. One such tool &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-2584","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/2584","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=2584"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/2584\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=2584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=2584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=2584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}