Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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)

share|improve this question

4 Answers 4

up vote 3 down vote accepted

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%.

share|improve this answer

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.

share|improve this answer

Based on the information provided here: http://linux.about.com/library/cmd/blcmdl1_yes.htm

Linux / Unix Command: yes

Command Library

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 ALSO

The 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.

share|improve this answer
    
I don't have a lot of Linux experience, how do you could use the "yes" command inside a process/script? –  Greg Treleaven Oct 24 '11 at 18:16
    

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.

share|improve this answer
    
why would you do an iterative rm if you use yes to delete everything? –  fromnaboo Apr 7 '13 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. –  daniel kullmann Apr 8 '13 at 7:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.