opscape

Shell builtins

yes

Print a line (y by default) over and over until killed or the reader stops reading.

yes [STRING...]

8 of 8 examples run in Debian 13.7 on 2026-10-31 · coreutils 9.7-3 · manual: yes(1)

yes writes y and a newline, forever. Given arguments, it repeats them instead, joined by spaces. It stops when whatever reads its output closes the pipe, which is why yes | head -3 finishes instantly: head exits after three lines and yes is killed by SIGPIPE on its next write.

Its original job is answering prompts: piping yes into a command that asks "are you sure?" answers every question. Today most tools have a flag for that (apt-get -y, rm -f, cp -f), which is better because it is explicit. The other job is generating repeated input quickly: test files of a given size, or a fixed number of identical lines.

Examples

Print y repeatedly

yes | head -n 3
explain
output
y
y
y

Without head this would scroll until you press Ctrl-C.

Repeat your own text

yes 'all good' | head -n 2
explain
output
all good
all good

Any arguments replace y. Several arguments are joined with spaces.

Answer every prompt of an interactive command

Setup run before this example
touch a.tmp b.tmp c.tmp
yes | rm -i *.tmp
ls *.tmp
outputexit 2
rm: remove regular empty file 'a.tmp'? rm: remove regular empty file 'b.tmp'? rm: remove regular empty file 'c.tmp'? ls: cannot access '*.tmp': No such file or directory

rm -i asks before each file; yes answers y to all three. The prompts are printed without newlines because the answers come from the pipe, not the keyboard. The final ls fails because the files are gone.

Answer no to every prompt

Setup run before this example
touch a.tmp b.tmp
yes n | cp -i notes.txt a.tmp 2>&1; echo
cmp -s notes.txt a.tmp || echo "a.tmp was not overwritten"
output
cp: overwrite 'a.tmp'? 
a.tmp was not overwritten

yes n declines every question. cp -i asked before overwriting a.tmp, got n, and left the file alone.

Make a file with N identical lines

yes 'GET /health 200' | head -n 1000 > requests.log
wc -l requests.log
sort requests.log | uniq -c
output
1000 requests.log
   1000 GET /health 200

Handy for load-testing a parser or checking how a tool handles repetition.

Make a file of an exact size

yes 'lorem ipsum' | head -c 1M > big.txt
ls -l big.txt
output
-rw-r--r-- 1 dev dev 1048576 Oct 31 20:22 big.txt

head -c 1M cuts the stream at exactly 1,048,576 bytes, mid-line if necessary. This is a quick way to make compressible test data; use /dev/urandom for incompressible data.

Generate empty lines

yes '' | head -n 3 | cat -A
explain
output
$
$
$

An empty string argument makes yes print bare newlines. cat -A marks each line end with $ so the empty lines are visible.

Measure how fast it writes

yes | head -c 500M | wc -c
explain
output
524288000

yes writes large buffers rather than one line at a time, so 500 MiB passes through the pipe in well under a second. This makes it a cheap way to test pipe throughput.

Common pitfalls

  • Running yes without something to stop it. In a terminal it floods the screen until Ctrl-C; redirected to a file it fills the disk. Always pipe it into a reader that stops, such as head.

  • Using yes | command where the command has an assume-yes flag. apt-get -y, rm -f and fsck -y are explicit and do not depend on how the prompt reads its input.

  • Expecting yes | to answer password prompts. Programs such as ssh and sudo read passwords from the terminal device, not from standard input.

GNU vs BSD and macOS

The examples above ran the GNU/Linux version. These are the differences that matter on macOS and the BSDs (written from their documentation, not run here).

  • BSD and macOS yes repeat only the first argument; GNU joins all arguments with spaces. Quote the text as one argument to get the same result everywhere.

Options worth knowing

A selection, described in our own words. For the full list, see yes(1) or yes --help.

OptionWhat it does
--helpPrint usage and exit.
--versionPrint the coreutils version and exit.

Related