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.
yes [STRING]...
Try it
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.
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
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
yesonly in a pipeline whose reader stops, or give it ahead -nortimeout. Run bare in a terminal, it prints until you press Ctrl+C. - SIGPIPE is the normal ending. In
yes | head -n 3,headexits, the nextyeswrite fails, and the kernel stops it. Withset -o pipefailthe pipeline's status becomes 141, which surprises people. Test withPIPESTATUS, or end the stage with|| true. - Prompts that read from the terminal (
/dev/tty), assudo,sshorpasswddo, cannot be answered byyes. It works only for programs that read standard input. - Prefer built-in options.
apt-get -y,rm -forcp -fare safer than pipingyesinto a command, becauseyesagrees to everything, including prompts you did not foresee. - A line is
STRINGplus newline. For a different terminator, useprintfin a loop;yes ''prints empty lines. - Speed: GNU
yesfills a big buffer and writes it in large chunks, soyes | pv > /dev/nullis a quick pipe benchmark.yes > filefills the disk, so never do that. - Making repeated text:
yes abc | head -n 3 | tr -d '\n'givesabcabcabc; this is a compact way to create a run of characters.