yes

Repeat a string (default: y) until stopped; useful for auto-confirming prompts and testing pipelines.

Category: Shell Utilities coreutils automation stdin pipelines testing

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 y if 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 yes supports -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

  1. Preview what yes produces
    yes | head -n 10
  2. Use a custom answer
    yes NO | head -n 5
  3. Auto-confirm a command that prompts (be careful)
    # Example: auto-confirm a benign prompt
    yes | some-command-that-prompts
  4. Limit the amount of output to avoid runaway pipelines
    yes | head -n 1000 > /tmp/yes_sample.txt
  5. Generate a quick stream of lines for testing filters
    yes "alpha" | grep -m 3 alpha
  6. Test how fast a consumer reads stdin
    yes | pv -L 1m | head -n 1000 > /dev/null
  7. Make a fixed-length stream of characters
    yes | tr -d '\n' | head -c 80; echo
  8. Create repeated tokens for a script
    # 20 lines of "ok"
    yes ok | head -n 20
  9. Use without newlines (GNU yes)
    # 50 characters of "y" (no newlines)
    yes -n y | head -c 50; echo
  10. 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/null for 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, yes typically terminates due to SIGPIPE.
  • On some minimal systems (BusyBox), yes may 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 piping yes.
  • For performance tests, consider generators like dd (bytes) or seq (numbers) depending on what you need.

Related Commands

  • head — limit output
  • timeout — stop after a duration
  • printf — controlled output formatting
  • seq — generate sequences
  • pv — rate/throughput monitor
  • tr — translate/delete characters
  • xargs — build and execute commands
  • tee — split output streams