https://www.howtoforge.com/linux-yes-command
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 yes, and in this tutorial, we will discuss this command with some easy to understand examples.
But before we do that, it's worth mentioning that all examples provided in this tutorial have been tested on Ubuntu 16.04 LTS.
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.
You can also provide a custom string for the yes command to use in output. For example:
For example, consider the following scenario:
Linux yes command
The yes command in Linux outputs a string repeatedly until killed. Following is the syntax of the command:
yes [STRING]...
yes OPTION
And here's what the man page says about this tool:yes OPTION
Repeatedly output a line with all specified STRING(s), or 'y'.The following Q&A-type examples should give you a better idea about the usage of yes.
Q1. How yes command works?
As the man page says, the yes command produces continuous output - 'y' by default, or any other string if specified by user. Here's a screenshot that shows the yes command in action: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.
You can also provide a custom string for the yes command to use in output. For example:
yes HTF
Q2. Where yes command helps the user?
That's a valid question. Reason being, from what yes does, it's difficult to imagine the usefulness of the tool. But you'll be surprised to know that yes can not only save your time, but also automate some mundane tasks.For example, consider the following scenario:
You can see that user has to type 'y' for
each query. It's in situation like these where yes can help. For the
above scenario specifically, you can use yes in the following way:
yes | rm -ri test
So the command made sure user doesn't have
to write 'y' each time when rm asked for it. Of course, one would argue
that we could have simply removed the '-i' option from the rm command.
That's right, I took this example as it's simple enough to make people
understand the situations in which yes can be helpful.
Another - and probably more relevant - scenario would be when you're using the fsck command, and don't want to enter 'y' each time system asks your permission before fixing errors.
No comments:
Post a Comment