Software:yes (Unix)
Example usage of yes command which prints "wikipedia" continuously until killed | |
Operating system | Unix and Unix-like |
---|---|
Platform | Cross-platform |
Type | Command |
License | coreutils: GPLv3+ |
yes
is a command on Unix and Unix-like operating systems, which outputs an affirmative response, or a user-defined string of text, continuously until killed.
Overview
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). However, if the user enters a string after 'yes,' yes will output the string the same as it would 'y,' similar to echo.
The version of yes
bundled in GNU coreutils was written by David MacKenzie.[1]
The command is available as a separate package for Microsoft Windows as part of the GnuWin32 project[2] and the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.[3]
Uses
yes
can be used to send an affirmative (or negative; e.g. yes n
) response to any command that would otherwise request one, thereby causing the command to run non-interactively.
Piping 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
$ yes | sudo apt install foobar
will answer the prompts for confirmation with y, effectively installing foobar with sudo apt 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., rm -f
) or an 'assume-yes' option (for example,apt -y
).
As an example, the following:
$ rm -f *.txt
is functionally equivalent to
$ yes | rm *.txt
The yes
command in conjunction with the head command can be used to generate large volume files for means of testing. For example, executing
$ yes 1234567 | head -n1000 > file
results in a file consisting of 1000 lines each consisting of eight characters (1, 2, 3, 4, 5, 6, 7 and newline).
yes
can be used as an easy way of generating CPU load. In 2006, for example, the yes
command received publicity for being a means to test whether or not a user's MacBook is affected by the "Intermittent Shutdown Syndrome" bug, where a MacBook would randomly shut off without any user input. By running the yes
command indefinitely twice via Terminal under Mac OS X, users were able to max out their computer's CPU, and thus see if the failure was heat related.[4][5]
Implementation and performance
The implementation of yes
on different Unix and Unix-likes was consistently implemented with a simple while-loop. The GNU Project's implementation of yes
was much faster than any other implementation, achieved by buffering its output, leading to more output per system call.[6][7] GNU's implementation may have been different to avoid infringing on the Unix copyright. The FreeBSD Project changed their implementation in 2017 to match GNU's implementation.[8]
References
- ↑ Linux User Commands Manual –
- ↑ CoreUtils for Windows
- ↑ Native Win32 ports of some GNU utilities
- ↑ "Test for MacBook Random Shutdown Syndrome (RSS)". 2006-08-29. http://www.zdnet.com/blog/apple/test-for-macbook-random-shutdown-syndrome-rss/274.
- ↑ "Testing your MacBook for Random Shut Downs". the apple files. 2006-08-02. http://techpaedia.com/apple/2006/08/27/testing-your-macbook-for-random-shut-downs/.
- ↑ Endler, Matthias (2017-10-10). "A Little Story About the 'yes' Unix Command". https://matthias-endler.de/2017/yes/.
- ↑ kjensenxz (2017-06-13). "r/unix - How is GNU 'yes' so fast?" (in en-US). https://www.reddit.com/r/unix/comments/6gxduc/how_is_gnu_yes_so_fast/.
- ↑ gahr (2017-06-13). "Improve yes' throughput" (in en-US) (commit). https://github.com/freebsd/freebsd-src/commit/dadfd1ed33e4ca779998ddeca7d5b0bb30098543#diff-7522fadfdb72e9638d4e91408a9f26dd5a4dace7b5c5f91cc73d86af23c8867d.
Further reading
External links
- Manpage for
yes
(GNU version) - GNU coreutils yes.c implementation
- FreeBSD yes.c implementation
- NetBSD yes.c implementation
- OpenBSD yes.c implementation
Original source: https://en.wikipedia.org/wiki/Yes (Unix).
Read more |