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:
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).
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: http://linux.about.com/library/cmd/blcmdl1_yes.htm
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 yes
should 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.
-
I don't have a lot of Linux experience, how do you could use the "yes" command inside a process/script? Commented Oct 24, 2011 at 18:16
-
See this: askubuntu.com/questions/71566/what-is-the-yes-command/… Commented Oct 24, 2011 at 18:44
The 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.
-
1why would you do an iterative rm if you use yes to delete everything? Commented Apr 7, 2013 at 1:37
-
@fromnaboo It's a bad example, I know. But sometimes you do not have access to the internal working of a program you have to use, and so yes can help you avoid endlessly repeating the same input. Commented Apr 8, 2013 at 7:07
-
1