Today (well, earlier this week but let’s not be picky here) I learned about the Unix core utility
It works like this:
$ yes y y y # [ad infinitum until stopped]
$ yes no no no no # [ad infinitum until stopped]
As you can see,
yes either prints
y\n until stopped or whatever string you pass it followed by a newline,
again continuing until the process is killed.
What is this good for?
At first, I had no clear idea what
yes could be used for but after some research, the following use cases appeared:
- repeatedly answer yes (or no, or whatever) via stdin to commands that require user input, e.g., to
apt install something
- write repeated lines to a file
$ yes "Hello test" | head -n 100 > test.txt
- getting CPU load to 100% for load testing - essentially
yesis just a
yes to your toolbelt, if this sounds useful.
Thanks for reading and let me know if you found other good use cases for