Linux yes command

Updated: 05/04/2019 by Computer Hope
yes command

On Unix-like operating systems, the yes command is used to output "y", continually, until it is aborted.

This document covers the GNU/Linux version of yes.

Description

The yes command outputs the same string, STRING, in a constant stream. If STRING is not specified, the word it repeats is "y".

yes dates back to a time before Unix commands included the "force" (-f) option, which for many commands is the same as answering "yes" to all prompts.

yes can be used to do something very similar: if the output of yes is piped to a command, it will effectively answer "yes" to any confirmation prompts.

Syntax

yes [STRING]...
yes [OPTION]

Options

--help Display a help message, and exit.
--version Display version information, and exit.

Examples

yes | rm -i *.txt

Removes all files with the extension .txt from the current directory. Here, yes outputs a constant stream of "y" characters, and that output is piped to the rm -i command, which prompts for confirmation before deleting each file. The y characters from the yes command will respond "yes" to each prompt automatically.

yes n | rm -i *.txt

Here, the yes command outputs "n" in a constant stream to the rm -i command, answering "no" to all the same questions. Therefore, this command deletes no files.

echo — Output text.