Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Text Processing

Linux yes command

Reference for the Linux yes command: print y or any string endlessly, answer prompts automatically, generate test data and stop with head or SIGPIPE.

yes writes a line containing y over and over, forever, until it is killed or its output pipe closes. Given arguments, it repeats those instead, joined by spaces.

The original purpose was to answer "are you sure?" prompts in scripts: yes | some-command. Today it is just as useful as a fast generator of test lines. It is very quick (gigabytes per second) so it also serves as a throughput test for pipes.

Terminal
yes [STRING]...

Try it

Bash Limited by head

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Answering prompts and building data

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
yes [STRING]...
yes OPTION
Argument Description
none Print y repeatedly.
STRING... Print the arguments joined by single spaces, repeatedly.
--help, --version Show help or version information and exit.

Returns: it normally never exits on its own; when its output closes it is terminated by SIGPIPE (shell status 141) or exits non-zero with a write error.

Usage notes

  • Always limit it. Run yes only in a pipeline whose reader stops, or give it a head -n or timeout. Run bare in a terminal, it prints until you press Ctrl+C.
  • SIGPIPE is the normal ending. In yes | head -n 3, head exits, the next yes write fails, and the kernel stops it. With set -o pipefail the pipeline's status becomes 141, which surprises people. Test with PIPESTATUS, or end the stage with || true.
  • Prompts that read from the terminal (/dev/tty), as sudo, ssh or passwd do, cannot be answered by yes. It works only for programs that read standard input.
  • Prefer built-in options. apt-get -y, rm -f or cp -f are safer than piping yes into a command, because yes agrees to everything, including prompts you did not foresee.
  • A line is STRING plus newline. For a different terminator, use printf in a loop; yes '' prints empty lines.
  • Speed: GNU yes fills a big buffer and writes it in large chunks, so yes | pv > /dev/null is a quick pipe benchmark. yes > file fills the disk, so never do that.
  • Making repeated text: yes abc | head -n 3 | tr -d '\n' gives abcabcabc; this is a compact way to create a run of characters.