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.
Resources
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
9 Comments
Join Our Newsletter
Categories
- Bash Scripting (17)
- Basic Commands (51)
- Featured (7)
- Just for Fun (5)
- Linux Quick Tips (98)
- Linux Tutorials (65)
- Miscellaneous (15)
- Network Tools (6)
- Reviews (2)
- Security (32)
I did not know what to expect. entertaining post!
An amusing article! Thank you!
Great article! A question how I could answer...?
yes
no
Any idea?
Thanks in advance.
I am not sure I understand your question. You want to answer yes then no ? Can you explain in more detail?
Hi Steven,
yes that's correct. I have to answer two prompts, in the first one I need to answer "yes", and in the second one "no", but if I use the "yes command" always answer "yes".
Any tip for to solve this?
Hi Steven,
that's correct! I need to answer two prompts. In the first one I need to respond "yes" and in the second one "no".
I've tried this combinations...
"yes no | pecl install -o -f redis"
"yes | no | pecl install -o -f redis"
"yes "no" | pecl install -o -f redis"
...but nothing works 🙁
Try something like this:
echo -e 'yes'"\n"'no' | pecl install -o -f redis
The words yes and no are wrapped in single quotes and the \n is wrapped in double quotes.
Thanks Steven, work like a charm!
FYI I found another way for to do it using a package called "expect"
Yes, expect will work also, just a little more involved. Good luck!