Linux命令之yes

 

在删除文件或进行一些乱七八糟的危险操做时总须要用户手动输入一个"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

相关文章
相关标签/搜索