在刪除文件或進行一些亂七八糟的危險操做時總須要用戶手動輸入一個"y"來肯定一下,可是若是數量不少的話手動輸入就是個災難啊,yes最初就是爲了解決這個問題產生的,好比這種形式:html
yes | rm a*
固然咱們能夠指定-f靜默選項不進行確認詢問,呃,就當我舉了個不太恰當的例子吧,畢竟我刪除文件歷來都是-f選項,而藉助yes的話太麻煩了。redis
不過它的另外一個用法可能大多數人都不知道,就是能夠指定一行字符串而後不斷將這行字符串送到標準輸出,實際上yes原本的做用就是接收一行字符串而後不斷將它輸出,若是未指定的話默認就是y,這個是寫在手冊裏的:shell
Repeatedly output a line with all specified STRING(s), or 'y'.
因此沒事啃下手冊仍是有些用處的,這個特性能夠將yes當作「crazy-repeat」使用(我瞎取的名字,不過還挺形象的),即將一行字符串不斷的重複輸出到標準輸出:this
yes "foobar"
在某些狀況下能夠用來模擬數據產生的過程,好比模擬日誌瘋狂產生的過程:日誌
yes "[2018-08-08 18:30:17] Thread-10 : foo bar"
總結:orm
1. yes用來將指定字符串不斷送到標準輸出,若是未指定字符串的話默認就是y,若是進程不被殺掉會一直髮送直到天荒地老。htm
2. 在某些狀況下能夠用來模擬不斷產生的數據,優勢是實現簡單,缺點是每行數據都是同樣的不會變,不如寫個腳本模擬。進程
最後附上文檔man yes:ip
YES(1) User Commands YES(1) 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 GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report yes translation bugs to <http://translationproject.org/team/> AUTHOR Written by David MacKenzie. COPYRIGHT Copyright © 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. 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 coreutils 'yes invocation' should give you access to the complete manual. GNU coreutils 8.22 April 2018 YES(1)
.ci