Install
# Most systems: yes is part of GNU coreutils (usually already installed) yes --version # RHEL / Alma / Rocky sudo dnf install coreutils # Debian / Ubuntu sudo apt install coreutils # openSUSE sudo zypper install coreutils # Arch sudo pacman -S coreutils
What it does
yes repeatedly prints a string (default: y) until it is stopped.
It is commonly used to auto-answer interactive “(y/n)” prompts or to quickly generate lots of input for testing pipelines.
How it works (mechanical)
- Builds an output line from the arguments (or
yif none). - Writes that line in an infinite loop to standard output.
- Stops when it receives a signal (Ctrl+C) or when the downstream command closes the pipe (SIGPIPE).
- Can be combined with
head,timeout, or rate limiters to prevent runaway output. - GNU
yessupports-n/--no-newline(output without the trailing newline).
Quick Start
# Print "y" forever (Ctrl+C to stop) yes # Print "yes" forever yes yes # Show the first 5 lines only yes | head -n 5 # Run for 2 seconds then stop timeout 2 yes > /dev/null
10 Practical Examples
- Preview what yes produces
yes | head -n 10
- Use a custom answer
yes NO | head -n 5
- Auto-confirm a command that prompts (be careful)
# Example: auto-confirm a benign prompt yes | some-command-that-prompts
- Limit the amount of output to avoid runaway pipelines
yes | head -n 1000 > /tmp/yes_sample.txt
- Generate a quick stream of lines for testing filters
yes "alpha" | grep -m 3 alpha
- Test how fast a consumer reads stdin
yes | pv -L 1m | head -n 1000 > /dev/null
- Make a fixed-length stream of characters
yes | tr -d '\n' | head -c 80; echo
- Create repeated tokens for a script
# 20 lines of "ok" yes ok | head -n 20
- Use without newlines (GNU yes)
# 50 characters of "y" (no newlines) yes -n y | head -c 50; echo
- Combine with timeout in automation
# Provide input for up to 1 second (then stop) timeout 1 yes | your-command
Notes & Gotchas
- It never stops on its own. Always pair with
head,timeout, or a command that will close the pipe. - It can spike CPU and generate huge output. Redirect to
/dev/nullfor throughput tests and use rate limiting if needed. - Dangerous with destructive commands. “Auto-confirm” can turn a harmless prompt into a fast mistake.
- If the downstream command exits,
yestypically terminates due to SIGPIPE. - On some minimal systems (BusyBox),
yesmay have fewer options than GNU coreutils.
Historical Context
The yes utility dates back to early Unix toolsets as a simple way to feed repeated input into programs.
GNU coreutils provides the modern implementation found on most Linux distributions.
Modern Equivalent
- If you only need a finite number of answers, prefer explicit input:
# 5 times printf 'y\n%.0s' {1..5} - Many tools provide a dedicated “assume yes” flag (often
-y) which is safer than pipingyes. - For performance tests, consider generators like
dd(bytes) orseq(numbers) depending on what you need.