Linux yes command

Updated: 04/26/2017 by Computer Hope

About yes

The yes command is used to output "y", or whatever word you choose, forever.

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.

yes syntax

yes [STRING]...
yes [OPTION]

Options

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

yes 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.