For faster navigation, this Iframe is preloading the Wikiwand page for yes (Unix).

yes (Unix)

yes是一个Unix指令,会不断输出表示确定的回应(或用户指定的字符串)直到程序被结束。

描述

[编辑]

yes先输出“y”或者任何以指令列参数形式给出的字符串,再输出一个换行,并反复过程直到用户终止或程序遭终止。当作为管道接入其他指令时,程序在管道断开时结束(例如当另一程序完成执行时)。

此指令也用于测试系统处理高负载的能力,因为yes会导致单处理器系统的处理器使用率维持在100%(对于多核心系统,进程必须为每个处理器执行),故可用于调查系统的冷却系统可否在处理器负载维持在100%时运作畅顺。

使用

[编辑]

yes可在需要用户应答的程序输出表示确定的回应(也可以输出否定的回应,如指令“yes n”),这样就可以使需要用户交互的指令以非交互形式运行。

这用法或许今天已经过时,因为大多询问用户回应的指令都有“force”参数(如“rm -f”)或“assume-yes”参数(如Debian及其派生系统的“apt-get -y”)

例如以下指令

   % rm -f *.txt

与以下指令

   % yes | rm *.txt

效果一样。

yes指令也常与head英语Head (Unix)指令配合用以产生大型文件供一些测试工作使用。如指令

   % yes 1234567 | head -1000 > file

可产生一份有1000行的文件,其中每行都有8字符(1,2,3,4,5,6,7与换行)。

2006年,yes指令因用于测试MacBook有否受间歇性关机问题影响而出名。在Mac OS XTerminal执行两次yes指令可将电脑CPU负载提升到最大,从而检查间歇性关机错误是否是散热问题造成。[1][2]

参考资料

[编辑]
  1. ^ Test for MacBook Random Shutdown Syndrome (RSS). 2006-08-29 [2012-05-09]. (原始内容存档于2014-11-13). 
  2. ^ Testing your MacBook for Random Shut Downs. the apple files. 2006-08-02 [2008-01-16]. (原始内容存档于2007-02-10). 

外部链接

[编辑]
{{bottomLinkPreText}} {{bottomLinkText}}
yes (Unix)
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?