I issued a command in the Ubuntu terminal that required me to type yes but I discovered that it only asks me the first time, but I had already pressed enter before I realized. So I expected a "command not found" message but instead I got a never-ending stream of "y"s. This seems to be the only thing this does, so I'm wondering what the point of this command is and why it outputs "y"s? (Ubuntu 11.10)
4 Answers
A long time ago (SySV days and earlier), the fsck command did not have -y or -n options. The command would interactively ask you to change hundreds or thousands of items, expecting a 'y' or 'n'. The yes command was created to pipe to fsck, and some other programs to be able to repeated answer the interactive questions (again, this was SysV days, long before Tcl and Expect). The yes program fit very well with the UNIX philosophy: small programs that do specific things very well and work with other programs.
From wikipedia:
0By 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).
It can also be used to test how well a system handles high loads, as using yes results in 100% processor usage, for systems with a single processor (for a multiprocessor system, a process must be run for each processor). This, for example, can be useful for investigating whether a system's cooling system will be effective when the processor is running at 100%.
Based on the information provided here:
Linux / Unix Command: yes
NAME
yes - output a string repeatedly until killed
SYNOPSIS
yes [STRING]... yes OPTION
DESCRIPTION
Repeatedly output a line with all specified STRING(s), or `y'.
--help display this help and exit --version output version information and exit
SEE ALSOThe full documentation for yes is maintained as a Texinfo manual. If the info and yes programs are properly installed at your site, the command
info yesshould give you access to the complete manual.
In my humble opinion, the usage of a "yes" command sounds logic when you have to repeatedly authorize something in a process/script by pressing the "y" key. Which can be controlled by cancelling the program execution.
Anyway, somebody else may have experience using this command.
2The yes command will either print its argument, or "y" if that is empty, until you end the program or its output pipe is closed. It can be used with programs that expect some repeated input, like rm -i.
3