If you are not familiar with the Linux yes command, you will be in 30 seconds. There isn't much to say about it, but I am known to ramble so challenge accepted. Let's have some fun...
The first version of the yes command was released with version 7 Unix and authored by Ken Thompson in 1979 (making it just 10 years younger than the rock Band of the same name) and contained a whopping 6 lines of code. It is (was?) still in active development as of 2016 and now is approx. 126 lines. As I was researching this tool I came across a few interesting pages that I will share in the resources section at the end of this, ummmm, article.
The yes command used by itself (without arguments) will just repeatedly output the letter "y" followed by a newline. It will continue relentlessly until you stop it or the process is otherwise killed. Yep... like that gnat that flies around your head at a cookout.
$ yes
y
y
y
y
y
y
y
...OUTPUT TRUNCATED...
If you pass an argument to the yes command, it will just print that string or strings to standard output indefinitely until stopped.
The yes command is relentless, it doesn't care what you think, it just does it's thing. Kind of inspirational if you ask me, like the O.G. Hipster of commands.
$ yes All work no play makes Jack a dull boy
All work no play makes Jack a dull boy
All work no play makes Jack a dull boy
All work no play makes Jack a dull boy
All work no play makes Jack a dull boy
All work no play makes Jack a dull boy
...OUTPUT TRUNCATED...
According to legend (Wikipedia) in 2006 the yes command was used to generate CPU load on MacBooks to test whether or not they were affected by the "Intermittent Shutdown Syndrome" bug. True Story.
Practical Uses for the Yes Command
The yes command has some practical uses aside from burning up old CPUs. It was originally conceived as a way to answer yes to interactive scripts when a user was to lazy to hit "y" when it needed an answer (joking). This is fairly obsolete today as most commands have built in switches to either answer yes ( -y ) or force ( -f ) the requested action.
Let's take a look at an example.
As a test, let's do an interactive rm and pass it the answer y using the yes command.
[savona@putor words]$ yes | rm -i Zyrian
rm: remove regular file 'Zyrian'? [savona@putor words]$
Well that worked. 🙂
You can also answer no, by conveniently typing:
$ yes no
no
no
no
no
...OUTPUT TRUNCATED...
Yes Command Examples
Here are some examples I found while surfing around:
Answer yes while fixing a filesystem with a lot of errors:
yes | fsck /dev/foo
Updating ports on a FreeBSD workstation:
yes | portmaster -da
Answer yes to installing software.
yes | dnf install <something>
And of course, CPU load testing! 🙂
Conclusion
I have been a Linux admin for almost 2 decades and I have never seriously needed to use the yes command. Don't get me wrong, I am not hating on it. I love nostalgia and after reading some of the interesting articles I came across, I can at least be thankful that it entertained me for an hour.
So if you are like me and enjoy reading interesting articles about antiquated commands, then here is a way to burn the next 10 minutes. Open the last link and play a song, then open the first link and read about a very interesting programming experiment.