Session and utilities

The yes command

Repeats a word or phrase endlessly, by default the letter y. Useful to answer the same.

Syntax

yes [texto]...Try it in the terminal →

Most useful options

--helpShows the help and exits.
--versionShows the version and exits.

Copy-ready examples

$ yes | head -n 3three lines of y.

Example output

y
y
y
$ yes vale | head -n 2with your own text.

Example output

vale
vale
$ yes uno dos | head -n 2several words are joined with a space on each line.

Example output

uno dos
uno dos
$ yes | tr -d '\n' | head -c 20; echoremoves the newlines and prints 20 characters in a row.

Example output

yyyyyyyyyyyyyyyyyyyy

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
yes: invalid option -- 'Q'yes only accepts --help and --version. Any other option, such as -Q, is an error.To repeat text that starts with a dash, put -- first: yes -- -Q.
yes: unrecognized option '--foo'A long option that yes does not recognize.Check the options with yes --help.

Typical mistakes

  • Without a pipe it never stops and floods the screen: always use | head or pipe it into a program that ends.
  • Several words are joined with one space on a single line: yes one two prints 'one two', not two lines.
  • If you pipe it into a program that asks for confirmation, it will answer yes to everything, including deletions. Test first with a throwaway target.

Differences from similar commands

  • echo: prints its arguments once. yes repeats the text endlessly.
  • seq: generates consecutive numbers up to a limit. yes always repeats the same text.

Related commands

FAQ

How do I answer no to every question?

Use yes no | program, which repeats no for every prompt. Check first what the program asks, because any answer is repeated.

How do I generate a test file of an exact size?

yes | head -c 1024 > test.txt creates exactly 1024 bytes of y and newlines. Change the number for another size.

Why does yes stop when I cut it off with head?

Because head closes the pipe after reading the lines you asked for, and yes finds out when it tries to write and ends by itself.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course