Ad space (banner)
🖥️Linux Lessons
Lesson 55 / 61

Repeating a String with yes

yes is for when "I want to output the same string repeatedly, to practice with pipes." yes repeatedly outputs the given string (or "y" if omitted), infinitely, until stopped.

Use it in the form yes string. Press Ctrl+C to stop it. Combining it with head to limit the line count is common.

Running yes practice fills the screen with the string "practice," endlessly. For learning purposes, limiting it with something like | head -5 is safer.

A common early mistake is running it with no line limit, flooding the terminal with a massive amount of output that's hard to work with. Always combine it with head while learning.

In real work, this is occasionally used in a script that wants to auto-answer every confirmation prompt with "y" (yes | command).

Linux
Try it (type this into the pseudo terminal)
yes practice

🧑‍💻 You can type this command into the Linux pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)