🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

yes Command

Beginner Shell Scripting man(1)

Output a string repeatedly until killed

👁 11 views 📅 Updated: Mar 15, 2026
SYNTAX
yes [STRING]

What Does yes Do?

yes outputs a string repeatedly until killed. Without arguments, it outputs "y" endlessly. With an argument, it outputs that string repeatedly. yes is primarily used to automatically answer confirmation prompts in scripts.

yes generates output as fast as possible, making it also useful for stress testing, generating test data, and filling pipes. It is a simple but essential automation tool.

In modern scripting, many commands offer -y or --yes flags for non-interactive confirmation, reducing the need for yes. But it remains useful for commands without such flags.

Options & Flags

OptionDescriptionExample
(no args) Output "y" repeatedly yes | head -5
STRING Output STRING repeatedly yes "I agree" | head -3
piped Auto-answer prompts yes | apt install package

Practical Examples

#1 Auto-confirm prompts

Automatically answers "y" to each rm confirmation prompt.
$ yes | rm -i *.tmp

#2 Custom string

Outputs "I accept" three times.
$ yes "I accept" | head -3
Output: I accept I accept I accept

#3 Auto-accept license

Automatically accepts all prompts during installation.
$ yes | ./installer.sh

#4 Generate test lines

Creates a 1000-line test file.
$ yes "test data" | head -1000 > testfile.txt

#5 Answer no

Automatically answers "n" to all prompts.
$ yes n | dangerous-command

#6 Fill disk (testing)

Creates a 100MB test file filled with "y\n" characters.
$ yes | dd of=testfile bs=1M count=100

Tips & Best Practices

Use command flags instead: Many commands have -y or --yes flags: apt install -y, rm -f. These are cleaner than piping yes.
yes is very fast: yes outputs gigabytes per second. Always pipe to a command or limit with head to avoid filling disk/memory.
Can cause damage: yes | dangerous_command will answer y to ALL prompts without discrimination. Make sure you want to confirm everything.

Frequently Asked Questions

What does yes do?
yes outputs "y" (or a specified string) repeatedly until killed. It is used to automatically answer confirmation prompts in scripts.
How do I auto-confirm command prompts?
Pipe yes: yes | command. Or better, use the command's own flag: apt install -y, rm -f.
How do I stop yes?
Press Ctrl+C, or pipe it to a command that will close stdin when done: yes | head -10.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →