Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

This question concerns the yes command found in UNIX and Linux machines: Basically, what is the point (if any) and history of this tool? Are there practical applications for it? Can an example be shown where it is useful in a script or chained (via pipe or redirect) with another tool?

The manpage is below:

YES(1)                    BSD General Commands Manual                   YES(1)

NAME
     yes -- be repetitively affirmative

SYNOPSIS
     yes [expletive]

DESCRIPTION
     yes outputs expletive, or, by default, ``y'', forever.

HISTORY
     The yes command appeared in 4.0BSD.

4th Berkeley Distribution        June 6, 1993        4th Berkeley Distribution

Sample output:

$ yes why
why
why
why
why
^Cwhy
share|improve this question

marked as duplicate by Anthon, slm, terdon, rahmu, jasonwryan Nov 25 '13 at 16:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers 3

up vote 39 down vote accepted

It's usually used as a quick and dirty way to provide answers to an interactive script:

yes | rm -r large_directory

will not prompt you about any file being removed. Of course in the case of rm, you can always supply -f to make it steamroll the directory removal, but not all tools are so forgiving.

Update

A more relevant example of this that I recently came across is when you are fscking a filesystem and you don't want to bother answering y when prompted before fixing each error:

yes | fsck /dev/foo
share|improve this answer
1  
Does that mean that the yes output would cease once the rm is completed? –  Jaryd Malbin Nov 25 '13 at 8:23
7  
@JarydMalbin, yes, because that's the default behavior of SIGPIPE. –  cjm Nov 25 '13 at 8:25
2  
@JarydMalbin Yes it does. When rm stops reading from the pipe (read: completes), yes gets a SIGPIPE as in cjm's comment –  Joseph R. Nov 25 '13 at 8:26

Beside the main point mentioned in the previous answer the yes command can also be used to test high loads of CPU on a system. yes creates a process which acts as a dummy CPU loader and results in 100% processor usage. http://en.wikipedia.org/wiki/Yes_(Unix)

share|improve this answer
1  
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. –  Anthon Nov 25 '13 at 8:41
1  
@Anthon check this en.wikipedia.org/wiki/Yes_(Unix) –  coffeMug Nov 25 '13 at 8:42
8  
@Anthon, even presenting an diverted usage, this answer provides a practical application of the yes command so certainly answers the question. –  jlliagre Nov 25 '13 at 10:05
    
@Anthon I modified the answer to better explain the usage (also provided the link to the wiki page). –  coffeMug Nov 25 '13 at 10:12
1  
@jlliagre Maybe you should check the edit history before you comment on a (review based) comment. "You can put a rather high load on your cpu using this command! ;)" useful? I think the SE system correctly considered that low-quality and offered it for review. The system does not does not notify automatically reviewer or a comment provider of makes changes in a non-answer. –  Anthon Nov 25 '13 at 10:12

When updating ports on a FreeBSD workstation, using portmaster + yes becomes very handy:

yes | portmaster -da

That way you can let the machine update while you lunch and all the questions fill default to 'y,yes'

When rebuilding the world for 'make delete-old' and 'make delete-old-libs'.

this is a big time saver:

yes | make delete-old

and

yes | make delete-old-libs

Basically helps you to avoid typing / confirm certain operations that ask for a 'y' or 'yes'

share|improve this answer

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