<code>yes</code> is a command on Unix and Unix-like operating systems, which outputs an affirmative response, or a user-defined string of text continuously until killed by the user.
By itself, the <code>yes</code> command outputs 'y' or whatever is specified as an argument, followed by a newline repeatedly until stopped by the user or otherwise killed; when piped into a command, it will continue until the pipe breaks (i.e., the program completes its execution). However, if the user enters a string after 'yes,' yes will output the string the same as it would 'y,' similar to echo.
The version of <code>yes</code> bundled in GNU coreutils was written by David MacKenzie.
The command is available as a separate package for Microsoft Windows as part of the GnuWin32 project and the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.
<code>yes</code> can be used to send an affirmative (or negative; e.g. <code>yes n</code>) response to any command that would otherwise request one, thereby causing the command to run non-interactively.
Piping yes to a command with many user-confirmation prompts will automatically answer all of those prompts with "yes" (typing 'y' and pressing return).
The following commands
will answer the prompts for confirmation with y, effectively installing foobar with sudo apt without any prompts.
This usage may be obsolete today, as most commands that would request response from the user have either a 'force' option (e.g., <code>rm -f</code>) or an 'assume-yes' option (for example,<code>apt -y</code>).
As an example, the following:
is functionally equivalent to
The <code>yes</code> command in conjunction with the head command can be used to generate large volume files for means of testing. For example, executing
results in a file consisting of 1000 lines each consisting of eight characters (1, 2, 3, 4, 5, 6, 7 and newline).
<code>yes</code> can be used as an easy way of generating CPU load. In 2006, for example, the <code>yes</code> command received publicity for being a means to test whether or not a user's MacBook is affected by the "Intermittent Shutdown Syndrome" bug, where a MacBook would randomly shut off without any user input. By running the <code>yes</code> command indefinitely twice via Terminal under Mac OS X, users were able to max out their computer's CPU, and thus see if the failure was heat related.
The implementation of <code>yes</code> on different Unix and Unix-likes was consistently implemented with a simple while-loop. The GNU Project's implementation of <code>yes</code> was much faster than any other implementation, achieved by buffering its output, leading to more output per system call. GNU's implementation may have been different to avoid infringing on the Unix copyright. The FreeBSD Project changed their implementation in 2017 to match GNU's implementation.