yes is a Unix command, which outputs an affirmative response, or a user-defined string of text continuously until killed.
By itself, the yes 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.
yes can be used to send an affirmative (or negative; e.g. yes n) response to any command that would otherwise request one, thereby causing the command to run non-interactively.
As an example, the following:
rm -f *.txt
is functionally equivalent to
yes | rm *.txt
The yes command in conjunction with the head command can be used to generate large volume files for means of testing. For example, executing
yes 1234567 | head -1000 > file
results in a file consisting of 1000 lines each consisting of eight characters (1, 2, 3, 4, 5, 6, 7 and newline).
Yes can be used as an easy way of generating cpu load, for example in 2006, the yes command received publicity for being a means to test whether or not a user's MacBook is affected by the Intermittent Shutdown Syndrome. By running the yes 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.
- Montfort, Nick (January 2012). The Trivial Program “yes” (PDF) (Technical report). Cambridge, Massachusetts: Trope Tank. 12-01. Retrieved 2017-03-21.