Your support is very much appreciated. Thanks, guys!
AI Generated·May contain errors
Video Summary
AI Generated
This video explains the functionality and practical applications of the `yes` command in GNU coreutils. It demonstrates how the command outputs a string repeatedly to automate terminal prompts, test CPU load, and handle specific script requirements, while also covering how to terminate the process.
The yes command is part of the standard GNU coreutils package. What does the yes command do?
Well, it outputs a string repeatedly over and over again until you kill the command. Let me show you
exactly what I'm talking about here. If I type yes and I don't give it any other flags or options,
what this will do is it will continuously output y to the terminal over and over and over again
until I kill the command. If I type control C, it will kill that process. Let me clear that.
Now, what is the purpose of this? Why have something output y over and over again? It's
because a lot of times terminal commands and sometimes scripts, sometimes programs ask you
for information. They prompt you typically for a yes or no question where y is yes, n is no. And
in this case, if I use the yes command, I can continuously over and over again answer y to all
questions that come up in a particular script or program. For example, if I ran a sudo pacman-s
yu here on an Arch Linux machine, what would happen is sometimes it's going to ask me,
hey, do you actually want to do this? Yes or no, meaning maybe there's a program that is
no longer in the repos or it conflicts with another program. Hey, do you want to have this
program override another program? Whatever it might be, it'll ask some yes or no questions.
And if I just want to answer yes to everything, which can be dangerous, I don't necessarily
recommend that, but I could pipe yes into this sudo pacman-SYU command, and it will simply
automatically answer y to every yes or no question that comes up. That way, I don't have to.
And naturally that would work with all of your package managers. So if you're on,
you know, an Ubuntu or a Debian and you want to answer, you know, something with a, like,
the apt-get command or whatever, apt-get install, you know, name of program, you know, and you want
to answer yes in case you get a prompt or an update command or whatever it is, just use yes.
Yes, pipe, and then the command. One of the most common reasons I will use the yes command is
sometimes you will have a situation where you're constantly being asked yes or no about removing
files, the rm command, you know, maybe your rm file 1, file 2, file 3. And for me, I have my rm
command alias to always use the interactive flag. So my rm command is actually rm-i for the
interactive mode, meaning that, hey, if this file exists, prompt me yes or no before you delete it.
Right? And so it's going to ask me three different yes or no questions, one for file 1,
one for file 2, one for file 3, if they exist on the system. Well, I would just answer yes
right away if I know I'm going to answer yes to all of those remove prompts. Another interesting
use for the yes command, you will sometimes see people use yes to test the load on their computer,
the CPU load. For example, I could type yes and then use the right-pointing chevron, the greater
than sign, and maybe direct all the output over to slash dev slash null and then give it the
ampersand at the end. What this does is it's going to output y over and over again, over and over
again. Right? Because that's the default yes functionality, except I'm not going to have that
output to the terminal. I don't need to see it. I'm just going to have that output directed over
to slash dev slash null. That's just a place on the system where information just goes to die.
But that process will be running over and over and over again on my machine, and I could test
the CPU load on the machine if I really wanted to. I can run that command, and it's running.
That yes command is running right now. Now, how to kill that yes command that's running in the
background? Well, I could use the pkill command. I could pkill yes, for example, and you can see
that job 1 yes was terminated, and you can actually see it even gave me the full command
there. That was job 1 yes directed over into slash dev slash null. Another thing I could have
done, I could have also just done a kill PID as long as I had the process ID of that process.
Now, yes doesn't necessarily have to always output a y. You can actually specify the string
that you want yes to output. For example, if I want yes to output the word string, it's just
going to output that over and over and over again. That way, no matter what the prompt is, whatever
you're trying to always answer the question with, you can get that. For example, there are
many programs or shell scripts sometimes that will ask for a prompt, and the confirmation for the
prompt is for you to hit enter. Well, yes by itself is not going to work because that's not
the enter key. That's why. How would you do something for a shell script or a program that
needed a enter? Well, you would do yes, and then how about single quotes? One single quote, and
then another single quote with nothing in between. An empty string, basically. If I hit enter,
that's just printing a new line over and over again, which is essentially hitting enter over
and over again. That is useful to automate installations or scripts that repeatedly ask
you for enter. Let me kill that process. That is essentially it for the yes command, a very
simple command. There's not a lot of flags or options to it. If you want to learn more about
type man yes in the terminal to read the man page.