LinuxCommandLibrary

yes

Repeatedly output a string (default 'y')

TLDR

Repeatedly output "message"

$ yes [message]
copy

Repeatedly output "y"
$ yes
copy

Accept everything prompted by the apt-get command
$ yes | sudo apt-get install [program]
copy

Repeatedly output a newline to always accept the default option of a prompt
$ yes ''
copy

SYNOPSIS

yes [STRING...]
yes OPTION

PARAMETERS

STRING...
    The string (or multiple strings separated by spaces) to be printed repeatedly to standard output, followed by a newline. If no STRING is provided, the command defaults to printing 'y' followed by a newline.

--help
    Display a help message and exit. This option provides a brief overview of the command's usage and available options.

--version
    Output version information and exit. This shows the program's name, version, and licensing details.

DESCRIPTION

The yes command is a simple but powerful utility in Unix-like operating systems. Its primary function is to print a specified string, or the character 'y' by default, repeatedly to standard output until it is killed. This continuous output makes yes incredibly useful for automating responses to prompts from other commands.

For instance, it is often piped to commands that require user confirmation (e.g., 'y' or 'n'), effectively providing an automatic 'yes' answer to all prompts. This can be particularly helpful in scripts or automated environments where interactive input is not feasible. Beyond simple confirmations, yes can also be used to generate large files for testing purposes, or to flood a terminal with text, although these are less common applications. It's a fundamental tool for scripting and basic system automation.

CAVEATS

yes outputs continuously and indefinitely, consuming CPU cycles and potentially filling output buffers or even disk space if redirected to a file, unless explicitly terminated (e.g., with Ctrl+C) or piped to a command that eventually finishes.

While useful for automation, piping yes to commands that prompt for confirmation (like rm -i) can be dangerous if not used with extreme caution, as it will automatically confirm every destructive operation without user review.

GENERATING LARGE FILES FOR TESTING

The yes command can be effectively combined with other utilities like head or dd to quickly generate large files of repetitive content for testing disk I/O, file system performance, or network throughput. For example: yes A | head -c 1G > 1GB_file.txt would create a 1 Gigabyte file filled with the letter 'A'.

AUTOMATING CONFIRMATIONS

One of the most common and powerful uses of yes is to provide automatic 'y' (yes) responses to commands that prompt for user confirmation. This is typically done by piping its output to the interactive command, allowing scripts to run non-interactively. For example: yes | rm -i *.txt would delete all .txt files without prompting for each one.

HISTORY

The yes command is a fundamental Unix utility that has been part of the operating system since its early versions. Its simplicity reflects the philosophy of Unix tools doing 'one thing well'. It's a core component of the GNU Core Utilities package, ensuring its widespread availability across Linux distributions. While its function remains straightforward, its enduring utility in scripting and automation underscores its importance in the Unix toolkit.

SEE ALSO

cat(1), echo(1), dd(1), xargs(1)

Copied to clipboard