# Yes (Unix)

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Yes_(Unix)
> Markdown URL: https://mediated.wiki/source/Yes_(Unix).md
> Source: https://en.wikipedia.org/wiki/Yes_(Unix)
> Source revision: 1356563339
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{short description|Unix command}}
{{lowercase}}
{{Infobox software
| name                   = yes
| logo                   = 
| screenshot             = Yes-example-command.gif
| screenshot size        = 
| caption                = Example usage of {{code|yes}} command which prints "Wikipedia" continuously until killed
| author                 = 
| developer              = 
| released               = 
| latest release version = 
| latest release date    = 
| operating system       = [Unix](/source/Unix) and [Unix-like](/source/Unix-like)
| platform               = [Cross-platform](/source/Cross-platform)
| genre                  = [Command](/source/Command_(computing))
| license                = [coreutils](/source/coreutils): [GPLv3+](/source/GPLv3%2B)
| website                = 
}}
'''<code>yes</code>''' is a [command](/source/command_(computing)) on [Unix](/source/Unix) and [Unix-like](/source/Unix-like) [operating system](/source/operating_system)s, which outputs an affirmative response, or a user-defined [string](/source/string_(computer_science)) of text continuously until killed by the user.

==Overview==
By itself, the <code>yes</code> command outputs 'y' or whatever is specified as an argument, followed by a [newline](/source/newline) repeatedly until stopped by the user or otherwise [killed](/source/Kill_(Unix)); 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](/source/String_(computer_science)) after 'yes', yes will output the string the same as it would 'y,' similar to [echo](/source/Echo_(command)).

The version of <code>yes</code> bundled in [GNU](/source/GNU) [coreutils](/source/coreutils) was written by David MacKenzie.<ref>{{man|1|yes|die.net}}</ref>

The command is available as a separate package for [Microsoft Windows](/source/Microsoft_Windows) as part of the [GnuWin32](/source/GnuWin32) project<ref>[https://gnuwin32.sourceforge.net/packages/coreutils.htm CoreUtils for Windows]</ref> and the [UnxUtils](/source/UnxUtils) collection of [native](/source/Native_(computing)) [Win32](/source/Windows_API) [ports](/source/porting) of common [GNU](/source/GNU) Unix-like utilities.<ref>[https://unxutils.sourceforge.net/ Native Win32 ports of some GNU utilities]</ref>

==Uses==
<code>yes</code> can be used to send an affirmative (or negative; e.g. <code>yes n</code>) response to any command that would otherwise request one, thereby causing the command to run non-interactively.

[Piping](/source/Pipeline_(Unix)) yes to a command with many user-confirmation prompts will automatically answer all of those prompts with "yes" (typing 'y' and pressing return).

The following commands

<syntaxhighlight lang="sh">
$ yes | sudo apt install foobar
</syntaxhighlight>

will answer the prompts for confirmation with y, effectively installing ''foobar'' with [sudo](/source/sudo) [apt](/source/APT_(Debian)) without any prompts.

This usage may be obsolete today, as most commands that would request response from the user have either a 'force' option (e.g., <code>[rm](/source/Rm_(Unix)) -f</code>) or an 'assume-yes' option (for example,<code>[apt](/source/Advanced_Packaging_Tool) -y</code>).

As an example, the following:

<syntaxhighlight lang="sh">
$ rm -f *.txt
</syntaxhighlight>

is functionally equivalent to

<syntaxhighlight lang="sh">
$ yes | rm *.txt
</syntaxhighlight>

The <code>yes</code> command in conjunction with the [head](/source/Head_(Unix)) command can be used to generate large volume files for means of testing. For example, executing

<syntaxhighlight lang="sh">
$ yes 1234567 | head -n1000 > file
</syntaxhighlight>

results in a file consisting of 1000 lines each consisting of eight characters (1, 2, 3, 4, 5, 6, 7 and newline).

<code>yes</code> can be used as an easy way of generating CPU load. In 2006, for example, the <code>yes</code> command received publicity for being a means to test whether or not a user's [MacBook](/source/MacBook) is affected by the "Intermittent Shutdown Syndrome" bug, where a MacBook would randomly shut off without any user input. By running the <code>yes</code> command indefinitely twice via [Terminal](/source/Terminal_(macOS)) under [Mac OS X](/source/Mac_OS_X), users were able to max out their computer's CPU, and thus see if the failure was heat related.<ref>{{cite web|url=http://www.zdnet.com/blog/apple/test-for-macbook-random-shutdown-syndrome-rss/274 |archive-url=https://web.archive.org/web/20100605230641/http://www.zdnet.com/blog/apple/test-for-macbook-random-shutdown-syndrome-rss/274 |url-status=dead |archive-date=June 5, 2010 |title=Test for MacBook Random Shutdown Syndrome (RSS) |website=[ZDNet](/source/ZDNet) |access-date=2012-05-09 |date=2006-08-29 }}</ref><ref>{{cite web|url=http://techpaedia.com/apple/2006/08/27/testing-your-macbook-for-random-shut-downs/ |title=Testing your MacBook for Random Shut Downs |access-date=2008-01-16 |date=2006-08-02 |work=the apple files |archive-url=https://web.archive.org/web/20070210135333/http://techpaedia.com/apple/2006/08/27/testing-your-macbook-for-random-shut-downs/ |archive-date=2007-02-10 }}</ref>

== Implementation and performance ==
The implementation of <code>yes</code> on different Unix and Unix-likes was consistently implemented with a simple while-loop. The GNU Project's implementation of <code>yes</code> was much faster than any other implementation, achieved by buffering its output, leading to more output per system call.<ref>{{cite web |url=https://matthias-endler.de/2017/yes/ |title = A Little Story About the 'yes' Unix Command|first=Matthias|last=Endler|website=Endler.dev|date=2017-10-10|url-status=live|archive-url=https://archive.today/20220125141301/https://endler.dev/2017/yes/|archive-date=2022-01-25}}</ref><ref>{{Cite web|url=https://www.reddit.com/r/unix/comments/6gxduc/how_is_gnu_yes_so_fast/|title=r/unix - How is GNU 'yes' so fast?|author=kjensenxz|date=2017-06-13|archive-url=https://archive.today/20211030061115/https://www.reddit.com/r/unix/comments/6gxduc/how_is_gnu_yes_so_fast/|archive-date=2021-10-30|website=Reddit|language=en-US|url-status=live}}</ref> GNU's implementation may have been different to avoid infringing on the Unix copyright{{or|date=June 2025}}. The FreeBSD Project changed their implementation in 2017 to match GNU's implementation.<ref>{{Cite web|author=gahr|date=2017-06-13|url=https://github.com/freebsd/freebsd-src/commit/dadfd1ed33e4ca779998ddeca7d5b0bb30098543#diff-7522fadfdb72e9638d4e91408a9f26dd5a4dace7b5c5f91cc73d86af23c8867d|website=github|language=en-US|title=Improve yes' throughput|format=commit}}</ref>

==References==
{{Reflist}}

==Further reading==
*{{cite tech report |first=Nick |last=Montfort |author-link=Nick Montfort |title=The Trivial Program "yes" |number=12-01 |institution=Trope Tank |location=Cambridge, Massachusetts |date=January 2012 |url=https://tropetank.com/reports/TROPE-12-01.pdf |access-date=2022-02-08 }}

==External links==
*[http://man7.org/linux/man-pages/man1/yes.1.html Manpage for <code>yes</code>] ([GNU](/source/GNU) version)
*[https://github.com/coreutils/coreutils/blob/master/src/yes.c GNU coreutils yes.c] implementation 
*[https://github.com/freebsd/freebsd/blob/master/usr.bin/yes/yes.c FreeBSD yes.c] implementation
*[https://github.com/NetBSD/src/blob/trunk/usr.bin/yes/yes.c NetBSD yes.c] implementation
*[https://github.com/openbsd/src/blob/master/usr.bin/yes/yes.c OpenBSD yes.c] implementation

{{Unix commands}}
{{Core Utilities commands}}

Category:Unix software

---
Adapted from the Wikipedia article [Yes (Unix)](https://en.wikipedia.org/wiki/Yes_(Unix)) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Yes_(Unix)?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
